Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Since most open source projects include mod_rewrite rules to work with Apache I need to be able to convert them to work with lighttpd or nginx. Which web server allows me to convert the rules exactly to the equivalent from Apache? If both can be converted exactly which one has better syntax and advanced options that would better mimic Apache's?

For example I'll use a .htaccess from Wordpress.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
share|improve this question
up vote 7 down vote accepted

nginX seems to be the way to go if you're trying to retain the rewrite rules.

This could be done like this:

if (!-e $request_filename) {
  rewrite ^([_0-9a-zA-Z-]+)?(/.*) $2  break;
  rewrite ^([_0-9a-zA-Z-]+)?(/.*\.php)$ $2 last;
  rewrite ^ /index.php last;

But it seems like the power of nginX is to have less complex, smaller rules, so this might be a better way to replace that:

if (!-e $request_filename) {
  rewrite ^ /index.php last;
share|improve this answer
Wow, that's pretty easy, I like it. The more I see samples and claims about nginX, the more I want to try it. – lpfavreau Jun 3 '09 at 12:12
actually you should use try_files directive try_files $uri $uri/ /index.php; – yaplik Nov 20 '11 at 0:45

Just to make a complete answer for the next visitors, lighttpd does support rewrite rules although they don't support directly the equivalent of the -f and -d tags to verify the existence of a file and directory of the same name first.

There are currently three solutions:

  1. Wait until feature 985 is implemented into the standard distribution, which should normally happen in the next 1.4.23. Or patch your own version yourself.
  2. Use lighttpd's mod_magnet to test that.
  3. Place your static files in a fixed directory, such as medias, and make an exception for this directory, such as:

    $HTTP["host"] == "yoursite" {
        # all other config here ...
        alias.url = (
            "/medias" => "/var/www/yoursite/public/medias"
        url.rewrite-once = (
            "^/medias/(.*)" => "$0",
            "^/(.*)$" => "/index.php/$1",
            "^/$" => "/index.php",
share|improve this answer

Maybe look into "Cherokee" web server. Its a light, fast alternative to Apache and has some pretty nice features.

share|improve this answer

Regardless of which "light" webserver is faster (and they are all much faster then apache).. I will say this for Cherokee, the admin web interface is very easy to work with. Obviously, because it is web-based, the configuration is very different from apache. i would call It a pleasant different, not an irritating different.

but at the end of the day..., Only Apache is Apache. Apache's strength is its AAA-level flexibility.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.