正则表达式中匹配#的问题
Closed this issue · 7 comments
shenshunan commented
你安装的TeaWeb版本:
0.1.7.3
你的操作系统:
CentOS7
你的问题简介:
正则表达式中匹配#的问题
问题详细描述:
在URL转写中,写正则表达式匹配,遇到#会有问题。如:
原始url:http://abc.com/test/#/
想要重写为:http://abc.com/#/
不论怎么写正则,都无法将#识别,只要url中没有#,就都正常。
iwind commented
井号(#
)是浏览器端的锚点,任何浏览器都不会将其及之后的片段发送给服务器端,所以,当你访问 http://abc.com/test/#/ 的时候,相当于访问 http://abc.com/test/
shenshunan commented
我是想代理前端工程,因为前端是用Vue写的,他的路径一般都是 http://abc.com/#/user/login/这样的路径,我现在的需求就是将http://abc.com/webapp1/#/user/login/转写成http://abc.com/#/user/login/。这个就没法通过配置实现。
iwind commented
你只需要将 /webapp1/ 重写为 / 即可。
shenshunan commented
在重写规则里,匹配规则写的是 /webapp1/(.+) ,目标URL写 /${1},然后在下面的匹配测试中,输入测试的地址http://abc.com/webapp1/#/user/login/,会提示匹配失败,只要去掉测试地址的#,即可成功改写。(.+)这个正则也改了好几种形式了,也不行。
iwind commented
你可以按照我说的直接保存然后试试:将 /webapp1/ 重写为 /
因为#号不被认为是标准URL的一部分。
shenshunan commented
是因为之前看了日志,并没有跳过来,试验了很多以后,才到这个里面做匹配测试的
| |
木雨轩
|
|
邮箱:shenshunan@126.com
|
在2019年09月27日 08:00,Liu Xiangchao 写道:
你可以按照我说的直接保存然后试试:将 /webapp1/ 重写为 /
因为#号不被认为是标准URL的一部分。
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
iwind commented
在QQ或者微信群里吗?可以找我一下。