加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > Nginx > 正文

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

发布时间:2020-12-13 21:41:23 所属栏目:Nginx 来源:网络整理
导读:如何从带有参数的url中删除.html? 例如: http://www.domain.com/somepage.html?argument=wholebunch=a-lot 至: http://www.domain.com/somepage?argument=wholebunch=a-lot 我试过了 location / { index index.html index.php; rewrite ^.html(.*)$$1 la

如何从带有参数的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
     }

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

TNX

最佳答案
像这样修改你的配置:

# 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部分.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读