简体   繁体   English

使用mod_rewrite将URL中的%23替换为#

[英]Replacing %23 in URL with # using mod_rewrite

I have a GWT app in tomcat behind apache on linux. 我在linux上的Apache之后的tomcat中有一个GWT应用程序。 This maintains state inbound from a URL using parameters passed from a URL. 这使用从URL传递的参数来维护URL的状态入站。 See for example: 参见例如:

https://www.example.com/#anchor1?param1=foo&param2=bar https://www.example.com/#anchor1?param1=foo&param2=bar

I use a third party alerting package that is pushing a URL to the client but along the way it is encoding the URLs to 我使用了第三方警报程序包,该程序包将URL推送到客户端,但是在将URL编码为

https://www.example.com/%23anchor1?param1=foo&param2=bar https://www.example.com/%23anchor1?param1=foo&param2=bar

which means I am getting 404 errors. 这表示我收到404错误。

I have searched high and low for solutions and do not have a clear answer that works. 我在高处寻找解决方案,但没有一个有效的明确答案。

As far as I can work out I need a simple rule that replaces all occurrences of %23 with # in a URL but there seems to be no clear consensus on something that will work (believe me I have tried everything). 据我所知,我需要一个简单的规则,用URL中的#替换所有出现的%23,但似乎尚无明确的共识(相信我已经尝试了一切)。

What is the mod_rewrite rule to do this? 要执行此操作的mod_rewrite规则是什么?

Thanks in advance. 提前致谢。

By the time mod_rewrite sees it, # is decoded. 到mod_rewrite看到它时,#被解码。 Normal # are never sent to the server, so it's a simple as: 普通#永远不会发送到服务器,因此很简单:

RewriteRule ^(.*#.*) /$1 [R,NE]

I am assuming the browser needs the stuff after the #, so you have to redirect. 我假设浏览器需要在#号之后的内容,因此您必须重定向。 "NE" stops the # from being encoded on the way out. “ NE”阻止#在出局时被编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM