Retain anchor when redirecting subdomain (IE)

2019-04-13 03:12发布

问题:

Firefox:
http://example.com/about/#anchor -> http://www.example.com/about/#anchor

Internet Explorer 6-8:
http://example.com/about/#anchor -> http://www.example.com/about/

Why is the anchor dropped in IE and what can I do about it? (Query string is not dropped, only the #xyz part)

Is a PHP header or javascript redirect my only option? Thanks for all hints.

Update: Seems as the hash is not sent to the server. Would combining a PHP 301 header and a javascript redirect (with the location.hash) be a good solution?

回答1:

Had a similar problem in Tomcat/JSP, don't know about PHP. In Tomcat the rule was that the #anchor is only intended for the browser/user agent so you can't get it. My workaround was to use Javascript in the page instead to achieve the redirect. My tip would be that if you can't get it working in PHP soon then start trying a Javascript workaround.



回答2:

Anchors are never sent to the server, so no server-side solution can retain them.



回答3:

Only server side anchors can be used durring a server side redirect. They must have an ID (although I am not sure if they have to be created programatically)

Alternately you can pass a parameter and use the onload to move the focus to the ID or hyperlink.