Tutorial :Can we use & in url?



Question:

Can we use "&" in a url ? or should "and" be used?


Solution:1

Yes, you can use it plain in your URL path like this:

http://example.com/Alice&Bob  

Only if you want to use it in the query you need to encode it with %26:

http://example.com/?arg=Alice%26Bob  

Otherwise it would be interpreted as argument separator when interpreted as application/x-www-form-urlencoded.

See RFC 3986 for more details.


Solution:2

An URL is generally in the form

scheme://host/some/path/to/file?query1=value&query2=value  

So it is not advisable to use it in an URL unless you want to use it for parameters. Otherwise you should percent escape it using %26, e.g.

http://www.example.com/hello%26world  

This results in the path being submitted as hello&world. There are other characters which must be escaped when used out of context in an URL. See here for a list.


Solution:3

Unless you're appending variables to the query string, encode it.


Solution:4

encode '&' with & (this answer is based on your use of tags)

If you are asking what to use "&" or "and" when registering the name of your URL, I would use "and".

EDIT: As mentioned in comments "& is an HTML character entity and not a URI character entity. By putting that into a URI you still have the ampersand character and additional extraneous characters." I started answering before fully understanding your question.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »