I have read some postings on clean URLs with lighttpd and it seems I should use mod_magnet, but this is not available on my system and until I build my own server I need to work with mod_rewrite.

So the question is: can I get clean URLs by just using mod_rewrite? The answer seems to be yes. On the forum I found this recipe: http://drupal.org/node/50243#comment-127659.

My question is: can I just use this code fo drupal 5.1? It seems to contain specific code for the clean url test page. Is there anybody running a drupal 5.1 site on a lighttpd server using mod_rewrite who can tell me what to put in the httpd.conf file (that's where I assume these rewrite rules should go.

Comments

bzreef’s picture

Below is my lighttpd rewrite rules for drupal 5.1.

It was taken from the very same recipe you posted above and serves my needs perfectly.

   url.rewrite-final = ( "/rss.xml$" => "/index.php?q=rss.xml",
                          "^/([^.?]*)\?(.*)$" => "/index.php?q=$1&$2",
                          "^/search/(.*)$" => "/index.php?q=search/$1",
                          "^/([^.?]*)$" => "/index.php?q=$1",
                          "^/([^.?]*\.html)$" => "/index.php?q=$1",
                          "^/([^.?]*\.htm)$" => "/index.php?q=$1"
                        )
budojeepr’s picture

I guess it pays to have all you smart people around! :^)

I just tried your rewrite rules on FreeBSD 6.2, lighttpd 1.4.15, Drupal 5.2, PHP 5.2.

Works perfect. Thank you!

peterw’s picture

i am not very good at this kind of stuff, as hard as I have tried. I am wondering, how would this be modified if drupal was in a sub directory? I keep getting a page not found if i add my folder in before the index.php and after the ^.

davividal’s picture

I confirm that this is working fine in Drupal 6.x.

I'm using it on sub dir, so I just have to change the rewrite to my sub dir.

In fact, a simple sed solve the "issue":

sed "s;/;/sub/dir/to/drupal/;g" file_with_rewrite.rules -i.bak

ulfjack2’s picture

The config above doesn't handle image thumbnail generation.

In order to enable image thumbnails, you need to setup lighttpd such that it conditionally rewrites the URLs to the images styles if the file does not exist yet. Then drupal generates the file and subsequent requests are handled by lighttpd instead. Here's the config I'm using:

  url.rewrite-once = (
    "^/([^.?]*)\?(.*)$" => "/index.php?q=$1&$2",
    "^/([^.?]*)$" => "/index.php?q=$1",
    "^/rss.xml" => "/index.php?q=rss.xml",
  )
  url.rewrite-if-not-file = (
    "^/(files/styles/.*)\?(.*)$" => "/index.php?q=$1&$2",
    "^/(files/styles/.*)$" => "/index.php?q=$1",
  )

We've been struggling with this exact problem and it took a while to debug what was going wrong.

sodani’s picture

Is there a way to use one set of rules for multiple drupal sites? The block above assumes that drupal is installed in the web root but I have several drupal installations.

everyz’s picture

You will also want to use such simpler configuration:

 url.rewrite-final = (
    "^/([^.?]*(\.xml|\.html)?)(\?(.+))?$" => "/index.php?q=$1&$4"
 )

Took from here: http://drupalperformanceblog.com/drupal-lighttpd-rewrite-rules

karthick62’s picture

Hi, I have started using drupal on lighttpd for the few days.. My directory set up goes like this .
1./document-root/site
2./document-root/site/subsite1
3./document-root/site/subsite2

I am able to get the clean urls for the above sites using lua scripts. I have no problem on accessing the pages using both apache and lighttpd (using lua scripts)
But I got another site,like 4./document-root/site/subsite3/subsite3.1

When I click the pages on the subsite3 and subsite3.1
I am getting page not found errors when I use lighttpd. but it works fine with apache2. I want to know that if we can access a subdiirectory inside a subdirectory using lighttpd using clean urls ? Thanks in advance...