1
我想刪除php文件擴展名。所以我搜索並嘗試了這個代碼。重寫文件擴展名後Nginx服務器不重定向
它運作良好,但當我嘗試不存在的頁面。
它只是說「文件未找到」。在我寫'try_files $ uri ...;'之前它返回/404.html。
我試過try_files $ uri = 404;在.php $中,但所有頁面都返回到/404.html。
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name localhost;
root /var/www/html;
include /etc/nginx/default.d/*.conf;
location/{
try_files $uri $uri.html $uri/ @extensionless-php;
index index.html index.php;
}
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name;
include fastcgi_params;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
error_page 404 /404.html;
location = /40x.html {
root /var/www/html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /var/www/html;
}
}
我該如何解決這個問題?