nginx redirects 302 instead of rewrite 200
If a user requests any .php file on my webserver I want his request (e.g. he requested mysite.com/testfile.php) to be handled by index.php
In index.php I use $_SERVER['REQUEST_URI'] to see which page the user wants to see (e.g. /testfile.php), so the index.php can generate the appropri开发者_如何学JAVAate html-code. Notice that testfile.php doesn't need to exist.
My problem is that I always get a redirect 302 to / when I try to request testfile.php (as a result $_SERVER['REQUEST_URI'] is /). But what I want is a 200 OK for testfile.php and that index.php generates the right html-code for this.
This is a snippet from my buggy nginx.conf:
server {
[...]
root /home/test;
# When I go to mysite.com redirect my to mysite.com/
location = / {
index index.php;
}
# For any php file request: let index.php handle the request
location ~ \.(php)$ {
include fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME /home/test/index.php;
}
}
Anyone can help me out? Thanks.
If the files never exist you can do this:
try_files $uri $uri/ /index.php
you can also rewrite the request like this:
location / {
rewrite ^.*$ /index.php last;
}
in both cases you should be able to read the original request with PATH_INFO
or REQUEST_URI
.
Have a look at these links for some more suggestions: http://drupal.org/node/110224, http://michaelshadle.com/2010/08/20/front-controller-patterns-and-nginx/, Zend Framework on nginx
精彩评论