Nginx重写:使用参数从URL中移除.html

如何从参数中删除一个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 } 

和一堆其他的build议,但似乎无法使其工作….

TNX

像这样修改你的configuration:

 # 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; } 

当然,你可以添加任何caching设置等,但这应该足以去除.html部分。