【发布时间】:2021-02-01 07:56:14
【问题描述】:
尝试了 Stack 上的所有解决方案后,我无法删除 .php 扩展名。
我设法使 URL 可访问:www.mydomain.com/login 但用户始终可以将 URL 更改为 www.mydomain.com/login.php,我想避免这种情况。
这是我的配置的一部分:
location / {
try_files $uri $uri.html $uri/ @extensionless-php;
index index.html index.htm index.php;
}
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_intercept_errors on;
fastcgi_pass unix:/run/php/php7.3-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
}
location @extensionless-php {
rewrite ^(.*)$ $1.php last;
}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
【问题讨论】:
-
也许您可以使用路由器而不是使用网络服务器来提供文件?
-
我不喜欢用路由器
-
要从原始请求中删除
.php,请使用:if ($request_uri ~ ^(.*)\.php(\?.*)?$ { return 301 $1$2; } -
勾选this一个。
标签: php nginx url-rewriting