我怎样才能从带有参数的 URL 中删除 .html?
例如: http://www.domain.com/somepage.html?argument=whole&bunch=a-lot
到:
http://www.domain.com/somepage?argument=whole&bunch=a-lot
我努力了
location / {
index index.html index.php;
rewrite ^\.html(.*)$ $1 last;
try_files $uri $uri/ @handler;
expires 30d; ## Assume all files are cachable
}
以及许多其他建议,但似乎无法使其发挥作用......
谢谢
答案1
像这样修改您的配置:
# rewrite html extensions
rewrite ^(/.+)\.html$ $scheme://$host$1 permanent;
location / {
index index.html index.php;
# this way nginx first tries to serve the file as an .html although it doesn't have the extension
try_files $uri.html $uri $uri/ @handler;
}
当然,您可以添加任何缓存设置等,但这足以删除.html 部分。