1
希望有人能幫助我。 注意;對不起,可能英文不好;) 我試了幾個小時來設置我的配置,所以我的網站可以在沒有php擴展的情況下訪問,但會重定向任何帶有擴展名的請求,並且除去URL中的/ index。Nginx移除php擴展和索引從url
我已經到了每一個擴展將被刪除,仍然被php5-fpm解析的地步。
這裏是我當前的代碼:
server {
listen 80;
server_name example.com;
root /var/www/example.com;
index index.php;
<<unrelated Modulecode>>
rewrite ^(.*).php(.*)$ $1$2 permanent; # << forces index to be appended, so not exactly wanted
#rewrite ^/index$/permanent; >> results in infinity loop for indexpage
# location ~ ^(.*)(?<!(index)).php(.*)$ { # << even don't know how to at least except index...gwarz regex x|
# rewrite ^(.*).php(.*)$ $1$2 permanent;
# }
location/{
try_files $uri $uri/ @phprule;
}
location ~ \.php$ {
try_files $uri $uri/ 404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location @phprule {
rewrite ^(.*)$ $1.php last;
}
}
的註釋掉部分是有些絕望改掉得到它在某種程度上工作X <
所以,我要完成的任務:
example.com /index.php => example.com/
example.com/foo.php => example.com/foo
example.com/some/path/foo.php => example.com/some/path/foo
希望你能明白。
哦,謝謝有人跑了同樣的問題,並試圖解決它,但你現在怎麼重定向到index(.php)本身? – KroniX 2015-10-20 16:31:55