nginx support for .htaccess / rewrite rules? Differences from Apache?
Solution 1:
nginx rewrite syntax is much cleaner then the counterpart in mod_rewrite:
mod_rewrite rule:
RewriteRule ^[a-z0-9_-]*-f([0-9]+)/?(p([0-9]+)\.html)?$ /viewforum.php?f=$1&start=$3 [QSA,L,NC]
Becomes in nginx:
rewrite ^/[a-z0-9_-]*-f([0-9]+)/?(p([0-9]+)\.html)?$ /viewforum.php?f=$1&start=$3 last;
But no .htaccess support...
Edit: Another example how to support http://example.com/~username/ urls in nginx:
location ~ /~([a-zA-Z0-9]*)/(.*) {
root /home/;
autoindex on;
index index.html;
rewrite ^/~([a-zA-Z0-9]*)/(.*)$ /$1/www/$2 break;
}
Solution 2:
It would appear that nginx does have a mod_rewrite equivelent and documentation can be found here. I've not used nginx myself, but the documentation looks like the configuration is totally different, but it shouldn't be too hard to understand what it's doing. The wiki appears to have plenty of examples.
I can't answer if you can have per directory configuration files like you can with apache. It wouldn't surprise me if you could, because people have come to expect that from using apache.
Solution 3:
nginx does provide rewrite functionality, check NginxHttpRewriteModule
What do you want to do with .htaccess? You can setup nginx for Basic Authentication with NginxHttpAuthBasicModule but AFAIK configuration directives can only be stored in nginx.conf