views:

137

answers:

4

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

+2  A: 

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

Jonathan Sampson
+1  A: 

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.

MarkPowell
*Face palm* Right, posted before thinking that through. Down vote as appropriate.
MarkPowell
Just delete your answer instead of asking for down votes :)
truppo
dangph
outis
+6  A: 

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.

frenetisch applaudierend
You don’t need to encode it when used in the URL path.
Gumbo
frenetisch applaudierend
+3  A: 

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.

Gumbo