Correct request redirection in Nginx
Igor Sysoev in the nginx-ru newsletter writes:
The other day I was wondering how to redirect requests to Drupal and others.
So, the Apachev construction of the form
RewriteCond% {REQUEST_FILENAME}! -F
RewriteCond% {REQUEST_FILENAME}! -D
RewriteRule ^ (. *) $ Index.php? Q = $ 1 [L, QSA]
needs to be redone not in
location / {
if ( ! $ request_file) {
rewrite ^ (. *) /index.php?q=$1 last;
}
}
location = /index.php {
fastcgi ...
}
and not even in
location / {
error_page 404 = /index.php?q=$request_uri;
}
location = /index.php {
fastcgi ...
}
but in this:
location / {
error_page 404 = drupal ;
}
location = drupal {
fastcgi_param SCRIPT_FILENAME /path/to/index.php;
fastcgi_param QUERY_STRING q = $ request_uri;
fastcgi ...
}