
如何從帶有參數的 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 部分。