[英]Rewrite all requests for non existing files to index.php with try_files with Nginx
[英]Nginx Rewrite Rule for all .PHP files/requests to be parsed by index.php
nginx能夠重寫像'/submit.php'這樣的URL以便能夠從index.php處理它們,這是否是一種神奇的重寫(就像在Apache上一樣)? 由於網站結構的原因,我們有很多404未找到錯誤,所有以前的URL都像'/addrate.php'、'/my_settings.php'、'/profile.php'->此類文件超過50個,並且為這些函數中的每個函數創建一個單獨的.php文件,而不是像通過其他重寫一樣通過index.php並使用所需的類來解析它們,這將是非常不專業和代碼不明智的。
您能否找到解決方案/今天就此給我們建議?
我認為有關此的一些信息在這里,但我希望得到完全相反的結果: http : //www.nullis.net/weblog/2011/05/nginx-rewrite-remove-file-extension/
此配置使您可以使用放在/var/www/example.org/htdocs/index.php
一個php腳本處理所有URL(文件系統中不存在的文件)。
server {
listen 80; ## listen for ipv4
server_name example.org www.example.org;
root /var/www/example.org/htdocs;
access_log /var/log/nginx/example.org.access.log;
error_log /var/log/nginx/example.org.error.log;
location / {
index index.php index.html index.htm;
try_files $uri $uri/ @php;
}
# enable running php files under php fastcgi
location ~ \.php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/example.org/htdocs$fastcgi_script_name;
#fastcgi_param QUERY_STRING $uri;
include fastcgi_params1;
}
location @php {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/example.org/htdocs/index.php; # this script catches all non existing URLs
fastcgi_param QUERY_STRING $uri;
include fastcgi_params1;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.