English 中文(简体)
这个网址是无效的,不是好的做法吗?
原标题:is this url unvalid and not good practice?

我有一个如下格式的url:

http://www.example.com/manchester united

注意曼彻斯特和曼联之间的空隙,这是糟糕的做法,还是完全好,我只是想在继续之前,谢谢

最佳回答

在URI中,空格不是有效字符;您必须将其替换为%20。这也可能被视为不良做法。最好将空格替换为-+_;它既“漂亮”又不需要转义URI。

大多数浏览器仍然会尝试使用空格来解析URI;但这是非常模糊的。

问题回答

It s bad practice not only because browsers are required to turn the space into a %20 and thus obfuscate your users address bars, but because it would be difficult to communicate the url to anyone. Furthermore, what about all of those "find links in text" regexes that are around stack overflow? You effectively break them all!

它将在地址栏中被替换为http://www.example.com/manchester%20united,我个人认为这比其他选择要丑陋得多http://www.example.com/manchester_united

我相信URLS中的空格被许多浏览器用%20符号取代了。

你需要添加%20而不是空格,但浏览器会为你添加,我宁愿在URI中没有空格

从技术上讲,这是可行的。浏览器将用%20替换空格,服务器将其翻译回。

但是这通常不是一个好主意,因为它可能会导致歧义,或难以与他人交流URL,尤其是在广告环境中,你希望有人输入他们在印刷品中看到的URL。

也许是一个问题:https://webmasters.stackexchange.com/

但是

如果你在浏览器中输入than,它将在曼彻斯特和曼联之间添加%20。从技术上讲,你应该在HTML页面中这样做,但大多数现代浏览器都可以处理。通常的做法是用连字符将它们分开,即http://www.example.com/manchester-united

请查看此问题的URL,以获取实际操作中的示例。

可以这样做,但显然这是一种糟糕的风格。

请参阅以下内容:http://www.blooberry.com/indexdot/html/topics/urlencoding.htm





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签