【发布时间】:2019-09-27 13:33:30
【问题描述】:
我正在尝试修改我的 NGINX 配置,以便在将 URI 的 .html 扩展名传递给基于 PHP 的 CMS 之前将它们剥离。
换句话说,当访问者进入时:
http://www.example.com/foo.html
我希望将 URI 更改为 /;
没有进行实际的浏览器重定向。这在 Apache 中很容易完成,但我似乎无法在 NGINX 中解决问题。这是我的配置文件中似乎不起作用的内容。
location ~ \.html {
rewrite ^(/.*)\.html(\?.*)?$ $1$2 last;
}
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
fastcgi_param REQUEST_URI $request_uri;
fastcgi_param SCRIPT_FILENAME $request_filename;
}
使用此代码,PHP 获取的 REQUEST_URI 仍然是 /foo.html。
【问题讨论】: