Reputation: 1136
It's kinda confusing to differenciate those three terms.
It'll be more understandable if you can explain with examples.
Upvotes: 0
Views: 374
Reputation: 38412
Old question, but deserves a better answer.
The terms 'encode/decode' and 'escape/unescape' may be used interchangeably by some, and PHP blurs the distinction, but they are somewhat different in Python and (I believe) Perl, where encoding (urllib.parse.urlencode) and decoding (urllib.parse.parse_qsl) refer only, or primarily, to the key-value pairs in a querystring, whereas escaping (urllib.parse.quote and urllib.parse.quote_plus) refers to replacing any "unsafe" characters with their %xx equivalent, e.g. ' '
becomes '%20'
:
>>> from urllib.parse import *
>>> quote('http://this.isa.test?hey=yo&this=that')
'http%3A//this.isa.test%3Fhey%3Dyo%26this%3Dthat'
>>> unquote(_)
'http://this.isa.test?hey=yo&this=that'
>>> 'http://this.isa.test?hey=yo&this=that'.split('?')[-1]
'hey=yo&this=that'
>>> parse_qsl(_)
[('hey', 'yo'), ('this', 'that')]
>>> urlencode(_)
'hey=yo&this=that'
urlencode calls a quote function to escape any necessary characters, by default quote_plus, which converts ' '
to '+'
instead of '%20'
. continuing with the previous python session:
>>> 'http://this.isa.test?hey=yo mama&this=#that?'.split('?', 1)[-1]
'hey=yo mama&this=#that?'
>>> parse_qsl(_)
[('hey', 'yo mama'), ('this', '#that?')]
>>> urlencode(_)
'hey=yo+mama&this=%23that%3F'
Upvotes: 0
Reputation: 4477
Url encoding and Url escaping are one and the same..
URL Encoding is a process of transforming user input to a CGI form so it is fit for travel across the network; basically, stripping spaces and special characters present in the url, replacing them with escape characters.
URL rewriting changes the way you normally associate urls with resources. Normally, test.com/aboutus makes us think that it will take us to the about us page. But internally, Server may take user 1 to /aboutus/page1.html, user 2 to /aboutus/page2.html or any other resource. The Url exposed to the end user will be test.com/aboutus but the resource being rendered can be different. Note that Url Rewriting is performed by Server.
Upvotes: 1