简体   繁体   中英

Replacing %23 in URL with # using mod_rewrite

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&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

https://www.example.com/%23anchor1?param1=foo&param2=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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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