nginx rewrite 写来不生效

我需要把

/module/index.html#/

转成

/index#/

不要前面的module

/module/merchant.html#/

转成

/merchant#/

我写的

rewrite ^/module/index.html(.*)$ /index#/$1;

直接404b

阅读 4.9k
2 个回答

#后面的数据是HTML页面处理的,而不是路由处理的,所以你的重写规则应该是:

rewrite ^/module/(.+)\.html$ /$1

就可以了。

你需要做的只是把.html/module/去掉而已。

另外,我不知道你是想地址写/module/index.html,来访问/index,还是地址写/index来访问/module/index.html,如果是后者的话,就不是上面那个了,应该是:

rewrite ^/(.+)$ /module/$1.html

不好意思,服务端拿不到 URL# 后面的数据, 这部分就只能在前端处理。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题