Salvete! I have discovered that a certain way of url encoding breaks the link. For the record %2f
represents the forward slash character: /
Now, consider this:
Original Link:
javascript (encodeURIComponent
) urlencoded link:
Now, if you paste the encoded link into your browser's address bar, it is broken (Firefox, Chrome, IE).
However, if you don't url-encode the first forward slash, it works perfectly:
'
Why?
Salvete! I have discovered that a certain way of url encoding breaks the link. For the record %2f
represents the forward slash character: /
Now, consider this:
Original Link: http://dottech/95285/this-is-the-pacific-barreleye-a-fish-with-a-transparent-head-amazing-photo-of-the-day
javascript (encodeURIComponent
) urlencoded link: http://dottech%2f95285%2fthis-is-the-pacific-barreleye-a-fish-with-a-transparent-head-amazing-photo-of-the-day
Now, if you paste the encoded link into your browser's address bar, it is broken (Firefox, Chrome, IE).
However, if you don't url-encode the first forward slash, it works perfectly:
'http://dottech/95285%2fthis-is-the-pacific-barreleye-a-fish-with-a-transparent-head-amazing-photo-of-the-day
Why?
Share Improve this question edited Feb 7, 2013 at 0:47 unor 96.9k28 gold badges225 silver badges381 bronze badges asked Jan 31, 2013 at 17:02 bgmCoderbgmCoder 6,3709 gold badges66 silver badges110 bronze badges 2- 1 To encode a plete URL use encodeURI- encodeURIComponent encodes pieces of an url location- protocol,host,port,pathname,hash and search – kennebec Commented Jan 31, 2013 at 17:09
- Related post - Is a slash (“/”) equivalent to an encoded slash (“%2F”) in the path portion of an HTTP URL & How to URL Encode a Backslash with R/RCurl – RBT Commented Jul 10, 2018 at 5:26
1 Answer
Reset to default 5The /
is a reserved character. It’s not equivalent to %2f
. If you need the slash without its defined meaning, you’d use the encoded form.
See RFC 3986: "Reserved Characters":
The purpose of reserved characters is to provide a set of delimiting characters that are distinguishable from other data within a URI. URIs that differ in the replacement of a reserved character with its corresponding percent-encoded octet are not equivalent. Percent- encoding a reserved character, or decoding a percent-encoded octet that corresponds to a reserved character, will change how the URI is interpreted by most applications.
The reason why the mentionend URL still works if you don’t use the reserved char /
for the second slash: their CMS simply looks for the ID part in the URL. So you can add whatever you want to the URL, e.g. the following should still work:
http://dottech/95285/hey-this-URL-got-featured-at-stackoverflow
(However, it seems that it still has to be /
or %2f
in their case.)
If you try it with a Wikipedia article, it redirects to the front page:
http://en.wikipedia/wiki%2fStack_Overflow
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745211677a4616879.html
评论列表(0条)