Nginx无扩展PHP重写不工作
我一直在尝试重写我的php页面,以便它们在浏览器中显示时不带扩展名。例如,我的服务器www.example.com上的链接加载了一个名为about-us.php的页面,在浏览器中,用户将看到www.example.com/about-us 我一直试图按照这些教程来尝试让它工作,但遗憾的是,它们没有工作 这是我的nginx站点可用/默认文件内容Nginx无扩展PHP重写不工作,php,nginx,url-rewriting,Php,Nginx,Url Rewriting,我一直在尝试重写我的php页面,以便它们在浏览器中显示时不带扩展名。例如,我的服务器www.example.com上的链接加载了一个名为about-us.php的页面,在浏览器中,用户将看到www.example.com/about-us 我一直试图按照这些教程来尝试让它工作,但遗憾的是,它们没有工作 这是我的nginx站点可用/默认文件内容 # Server Block server { # Listening Ports listen 80 default_server;
# Server Block
server {
# Listening Ports
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
# Root Location Initialization
root /home/zach/Documents/Workspaces/www;
index index.php index.html index.htm;
# Server Name
server_name localhost;
# Root Location
location / {
try_files $uri $uri/ @extensionless-php;
}
# Error pages
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /home/zach/Documents/Workspaces/www;
}
# PHP Handling
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
# Extensionless PHP
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
}
我所有指向php页面的链接仍在浏览器中显示.php扩展名,有人能解决我的问题吗?将以下行添加到您认为会形成循环的位置!:-
if ($request_uri ~ ^/([^?]*)\.php($|\?)) { return 302 /$1?$args; }
此处的更多信息:这个问题可能更适合@AlphaDelta。这个问题是关于nginx的-它直接涉及主要用于编程的工具肯定是服务器故障。@scrowler确切地说,这是关于nginx的问题,一个服务器软件,它不是编程或脚本问题。