4

I am confused about encoded URLs.

For example, when I write my browser:

stackoverflow.com/questions

I can successfully view the page.

However, when I write:

stackoverflow.com%2Fquestions

I am unable to view.

Since %2F means "/", I want to understand why this does not work properly.

The reason why I want to find out is that I am getting an encoded URL and I don't know how I can decode that URL right after I receive it in order not to have an error page.

yihlamur
  • 382
  • 1
  • 5
  • 17
  • 1
    I totally understand after reading your answers. What I am trying to do is that I am trying to pass a URL in a query string such as www.domain.com?retUrl=www.anotherdomain.com%3Fparameter%3D=value. Actually, I want to receive my parameter's value in anotherdomain.com. Is there a way to accomplish this? – yihlamur Nov 13 '11 at 21:53

5 Answers5

13

The / is one of the percent-encoding reserved characters. URLs use percent-encoding reserved characters for defining their syntax. Only when these characters are not used in their special role inside a URL, they need to be encoded.

Percent-encoding reserved characters:

!       *       '       (       )       ;       :       @       &       =       +       $       ,       /       ?       #       [       ]
%21     %2A     %27     %28     %29     %3B     %3A     %40     %26     %3D     %2B     %24     %2C     %2F     %3F     %23     %5B     %5D
Anne
  • 26,765
  • 9
  • 65
  • 71
  • I totally understand it now. What I am trying to do is that I am trying to pass a URL in a query string such as www.domain.com?retUrl=www.anotherdomain.com%3Fparameter%3D=value. Actually, I want to receive my parameter's value in anotherdomain.com. Is there a way to accomplish this? – yihlamur Nov 13 '11 at 21:48
  • 1
    For example, you can pass `http://www.example.com/example/` to `http://www.domain.com/page.php` by doing this: `http://www.domain.com/page.php?theURL=http%3A%2F%2Fwww.example.com%2Fexample%2F`. – Anne Nov 13 '11 at 21:57
  • Actually, domain.com is a service that I have no control and www.example.com is something that I control. domain.com redirects the browser to example.com. And, I want to receive a parameter in my example.com page (www.example.com?parameter=value). That is why I was thinking of using URL encoding/decoding. Do you have any idea how I can proceed? – yihlamur Nov 13 '11 at 22:02
  • I strongly recommend starting a new question where you explain the problem above (including example) and mention the programming language you're using. This way you will get the best answer. – Anne Nov 13 '11 at 22:12
  • I noticed your new question, unfortunately I have no experience with Salesforce Apex. Hopefully someone else can help! – Anne Nov 13 '11 at 22:37
  • @Anne I can understand that the `:` and `/` characters are reserved. But what are the `*`, `!`, `'`, `(`, `)`, `[`, `]` characters reserved for? – Pacerier Jul 04 '12 at 00:21
5

%2F is a URL escaped /. It means, treat / as a character, not a directory separator.

In essence, it is looking for a domain stackoverflow.com/questions, not the domain stackoverflow.com with the path questions.

Oded
  • 489,969
  • 99
  • 883
  • 1,009
1

%2F is what you write when you want to include a / in a parameter but don't want the browser to navigate to a different directory/route.

So if you had the file path 'root/subdirectory' passed as a querystring parameter, you would want to encode that like:

http://www.testurl.com/page.php?path=root%2Fsubdirectory

rather than

http://www.testurl.com/page.php?path=root/subdirectory

JHolyhead
  • 984
  • 4
  • 8
1

URL encoding is used e.g. for encoding a string URL parameter coming from an HTML form, which contains special characters, like '/'. Writing "stackoverflow.com%2Fquestions" is wrong, in this case the '/' is part of the URL itself, and must not be encoded.

kol
  • 27,881
  • 12
  • 83
  • 120
1

%2F is an escaped character entity - meaning it would be included in a name, rather than the character /, which denotes directory hierarchy, as specified in RFC 1630, page 8.

Nightfirecat
  • 11,432
  • 6
  • 35
  • 51