(Tutorial) Running Drupal with Clean URL on Nginx or Lighttpd
Tutorial : Running Drupal with Clean URL on Nginx or Lighttpd
First of all, my previous post on Nginx vs. Lighttpd for a small VPS seems to be a “hit”. Thanks to Glenn for submitting it to programming.reddit.com, which got picked up by a few bloggers. Got around 1,000 unique visitors on the day where the post went live, which I guess is pretty good for this one-post-a-week site of mine.
Since I have briefly touched on the “URL rewrite-ability” of Nginx and Lighttpd in my previous post, I think it might actually be useful to have some examples showing how rewrite rules are written on these web servers to support clean URLs. I will take the open source CMS Drupal for example, as it is what Hosting Fu runs on. Btw, Drupal 5.0 has just been released and it rocks.
Prerequisite
These are the things that I assume you would know before reading this article.
- Why clean URL. Pick your reason. SEO or general dislike of query string.
- Setting up PHP. I won’t be talking about how to set up PHP/FastCGI on Nginx or Lighttpd. Here’s one for Nginx and one for Lighttpd.
- Installing Drupal. Check related section in Drupal handbook.
I am only going to discuss the rewriting rules needed to enable clean URL in Drupal on either Nginx or Lighttpd.
Apache’s Mod_Rewrite
Like most open source PHP applications, Drupal came with a
.htaccessfile assuming Apache is serving the pages. We will use it as the reference on how the rewrite rules can be written for the other two web servers.Here’s the bit in
.htaccessthat does rewrites:RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
What it does is:
- If requested file exists, serve it.
- If requested directory exists, serve it depending on how index option is configured.
- Otherwise, send all requests to
index.php, setting parameter ‘q’ as the path of the original request, and then append the rest of the query string.Simple. Now let’s see how you can do the same with the other two web servers.
Courtesy : hostingfu.com
- guru's blog
- Login to post comments
![Drupal-6-Book-[Building Powerful and Robust Websites with Drupal 6].jpg](http://www.drupalranch.com/images/Drupal-6-Book-[Building%20Powerful%20and%20Robust%20Websites%20with%20Drupal%206].jpg)