使用mod_rewrite将URL中的%23替换为# [英] Replacing %23 in URL with # using mod_rewrite
问题描述
我在linux上的Apache后面的tomcat中有一个GWT应用程序.这使用从URL传递的参数来维护URL的状态入站.参见例如:
https://www.example.com/#anchor1?param1= foo& param2 = bar
我使用了第三方警报程序包,该程序包将URL推送到客户端,但是在将URL编码为的过程中
https://www.example.com/%23anchor1?param1= foo& param2 = bar
这意味着我收到404错误.
我在高处和低处寻找解决方案,但没有一个明确的答案.
据我所知,我需要一个简单的规则,用URL中的#替换所有出现的%23,但似乎尚无明确的共识(相信我,我已经尝试了一切). /p>
要执行此操作的mod_rewrite规则是什么?
谢谢.
在mod_rewrite看到它的时候,#被解码了.正常的#永远不会发送到服务器,因此很简单:
RewriteRule ^(.*#.*) /$1 [R,NE]
我假设浏览器需要在#号之后添加内容,因此您必须重定向. "NE"阻止#在出门时被编码.
I have a GWT app in tomcat behind apache on linux. This maintains state inbound from a URL using parameters passed from a URL. See for example:
https://www.example.com/#anchor1?param1=foo¶m2=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
https://www.example.com/%23anchor1?param1=foo¶m2=bar
which means I am getting 404 errors.
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).
What is the mod_rewrite rule to do this?
Thanks in advance.
By the time mod_rewrite sees it, # is decoded. 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.
这篇关于使用mod_rewrite将URL中的%23替换为#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!