Retain anchor when redirecting subdomain (IE)

好久不见. 提交于 2019-12-06 10:23:27

问题


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.



来源:https://stackoverflow.com/questions/2436742/retain-anchor-when-redirecting-subdomain-ie

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!