apache/nginx: .htaccess rewrite conversion mayhem
I am trying to rewrite an .htaccess rule from Apache to be used on a Nginx server.
RewriteCond $1 !^(index\.php|assets)开发者_如何学Python
RewriteRule ^(.*)$ /index.php/$1 [L]
Here is what I have which is sort of working, but some better direction would be much appreciated. I can hit the index and it loads ok and browse to assets folder fine, but deeper links do not work (PHP program is extracting vars from the URL to build db queries). I know i'm close.. thanks for any replies.
location / {
index index.php;
}
location /$ {
rewrite ^/(.*)$ /index.php/$1 last;
}
location /index.php {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
include fastcgi_params;
}
I think those rules will send everything that isn't under /assets to /index.php. I think this will do what you want. Also, it moves the root and index directives into the server, which is where they should be to be set as the default for all locations.
# set server defaults directly in server context
root /usr/share/nginx/html;
index index.php;
# location / is a fallback for any request that doesn't match
# a more specific location
location / {
rewrite ^ /index.php$uri last;
}
# Serve content under /assets from disk
location /assets {
}
# Extract path info and send /index.php for processing
location /index.php {
fastcgi_split_path_info ^(/index.php)(.*)
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_pass 127.0.0.1:9000;
}
精彩评论