Multiple hash signs in URL

∥☆過路亽.° 提交于 2019-12-18 18:53:39

问题


Or maybe you call it "sharp" - the # symbol.

I've came across one instance, where #! and # used simultaneously in a single URL. From reading other articles, including RFC, I can't understand whether that is a legal combination or not. When encountering such page Mozilla browser (Iceweasel in this case) displays the URL as having 2 #'s, while Chrome displays only one, but dies shortly afterwards (the tab containing the page becomes unresponsive and crashes - but it may not be connected).

Now, my question is, is it legal to have both in one URL, is it maybe legal and redundant (should be normalized), or is it just a bug in Mozilla browser? So, suppose I'm making an AJAX request, or trying to navigate the browser history - what should I do, if I encounter this situation?

RFC-3986: http://tools.ietf.org/html/rfc3986#section-3.4 , which should be clarifying it... just in case.

Also: https://developers.google.com/webmasters/ajax-crawling/docs/specification how Google crawlers see things.


回答1:


The format for a fragment only allows slashes, question marks, and pchars. If you look up the RFC, you'll see that the hash mark is not a valid pchar.

However, browsers will try their best to read non-valid URLs by treating repeat hashes as though they are escaped, as you can see by checking the value of window.location.hash (in IE, Firefox, and Chrome) for

http://www.example.com/hey#foo#bar

which is the same window.location.hash for

http://www.example.com/hey#foo%23bar



回答2:


It may be legal as @apsillers mentioned. But I would avoid it unless necessary as it can cause a certain confusion concerning the url.

That kind of url:

http://www.example.com/hey#foo#bar

Seems really confusing to me and will be even more confusing to regular users and maybe search engines.



来源:https://stackoverflow.com/questions/10850781/multiple-hash-signs-in-url

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