2

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]
</IfModule>
kovert
  • 437
  • 3
  • 8

4 Answers4

7

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;
}
Mike Fiedler
  • 2,162
  • 1
  • 17
  • 34
1

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",
        )
    }
    
lpfavreau
  • 439
  • 2
  • 8
  • 19
0

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

0

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.

J. M. Becker
  • 2,471
  • 1
  • 17
  • 21