Today's development company official website: http://www.zstime.com/, encountered a problem, how to set the PathInfo under Nginx and how to hide index.php
Here are the explanations for each:
First, Hidden index.php
Hide index.php need to modify Nginx configuration file, if you are using vhost, need to modify such as conf/vhost/your file name. conf
file, the entire file is as follows
server {Listen 80; server_name www.zstime.com; Index index index.html index.htm index.php; root/alidata/www/zstimebro/; Error_page 404/error.html; Location/{if ' (!-e $request _filename) {rewrite ^/(. *) $/index.php/$1 last; }} Location ~ \.php ($|/) {FASTCGI_PA SS 127.0.0.1:9000; Fastcgi_index index.php; Fastcgi_split_path_info ^ (. +\.php) (. *) $; Fastcgi_param path_info $fastcgi _path_info; Fastcgi_param script_filename $document _root$fastcgi_script_name; Include Fastcgi_params; } location ~.*\. (gif|jpg|jpeg|png|bmp|swf) $ {expires 30d; } location ~.*\. (JS/CSS)? $ {Expires 1h; } #α??????? include/alidata/server/nginx/conf/rewrite/default.conf; Access_log/alidata/log/nginx/access/default.log;}
It adds:
Location/{ if ' (!-e $request _filename) { rewrite ^/(. *) $/index.php/$1 last; } }
Redirect the request link, plus a index.php, to achieve the effect of removing index.php
Second, add pathinfo support
Nginx itself does not support pathinfo, all we need to parse the URL ourselves, will index.php
Location ~ \.php ($|/) { fastcgi_pass 127.0.0.1:9000; Fastcgi_index index.php; Fastcgi_split_path_info ^ (. +\.php) (. *) $; Fastcgi_param path_info $fastcgi _path_info; Fastcgi_param script_filename $document _root$fastcgi_script_name; Include fastcgi_params; }
Note: Adding PathInfo methods is more than one, but this method is relatively simple.
which
~ \.php ($|/)
Is the URL that contains the. php in the matching request path.
Third, add 404
404 page Add Toss a day, first need to open in nginx.conf
Fastcgi_intercept_errors on;
Remember to turn this on, or you won't be able to customize the 404 page.
After that, modify the vhost corresponding configuration file and add:
Error_page 404/error.html;
Remember that you cannot add the "=" sign.
So in theory is the end, but the browser to try to find or not, always show the status 200! A day's time is spent here!! Finally looked at for a long time, only to find that the problem is not a configuration file, but the problem of their own use of the framework, I use when brophp, this small framework actually did not do page 404 processing, well, reference to the http://www.csdn123.com/html/exception/ 693/693838_693845_693847.htm, it's done!
Summary: Sometimes, you think the problem of the place may be safe, you feel very safe place often out of question!