[Pmwiki-users] Ampersands in URI (was Re: AW: restore problem)

Christian Ridderström chr
Thu Feb 12 07:42:45 CST 2004


On Thu, 12 Feb 2004, Thomas -Balu- Walter wrote:

> > > > > http://www.mydomain.com/?pagename=Main.HomePage?action=attr
> > > > Amend to:
> > > > http://www.mydomain.com/?pagename=Main.HomePage&action=attr
> > > 
> > > http://www.mydomain.com/?pagename=Main.HomePage&action=attr
> > >                                                ^^^^^
> > > You should not use & in URLs, but their HTML entity...
> > > 
> > > e.g. http://example.com/electricity.php?volt=120&amp=7
> > > will definitely give some problems.

Actually, according to:

   http://www.w3.org/TR/html401/appendix/notes.html#ampersands-in-uris

you should use the '&' in the URI but the entitiy when writing HTML-code:

	For example, to use the URI "http://host/?x=1&y=2" as a linking 
	URI, it must be written <A href="http://host/?x=1&#38;y=2"> or
	<A href="http://host/?x=1&amp;y=2">.

so the *URI* uses '&' but the HTML-code needs an escaped '&'.

> > Why would that be a problem, there's no ';' after '&amp' in that URI?
> 
> AFAIK the & starts a html entity, no matter what follows. Some browsers
> recognize the unfinished "&amp" as "&amp;".

Well, what do you know... Opera recognizes "&amp" as "amp;" in HTML-code.


Anyway, to summarize this topic:

* If you want to code the URI as a link in HTML, you write:

  <a href="http://wiki.lyx.org/pmwiki.php?pagename=LyX.LyX&amp;action=attr">
  link text</a>

  where we have used '&amp;' since it's the HTML-entitity for '&'. It 
  is then then translated into a '&' in the resulting URI of the link.


* If you manually type the URI into your browser, use '&' like this:

	http://wiki.lyx.org/pmwiki.php?action=browse&pagename=Tips.Tips

  If you type the URI using '&amp;' it doesn't work:

	http://wiki.lyx.org/pmwiki.php?action=browse&amp;pagename=Tips.Tips

  Try it, you should be shown the default page (LyX.Welcome) rather than
  what you (thought you) specified (Tips.Tips).


* In an e-mail, write the URI using '&', like this:

	http://wiki.lyx.org/pmwiki.php?action=browse&pagename=Tips.Tips

  rather than

	http://wiki.lyx.org/pmwiki.php?action=browse&amp;pagename=Tips.Tips

  If I click on the URI with '&amp;' above, I am shown the default page
  instead of the page specified by pagename=Tips.Tips (same as typing it).


Finally, here are some links related to this topic:

* Writing HTML-code with links using ampersands:

  - http://www.w3.org/TR/html401/appendix/notes.html#h-B.2.2
  - http://www.w3.org/TR/html401/appendix/notes.html#ampersands-in-uris

 The latter link recommends using ';' instead of '&' to separate the form 
 values. Unfortunately this doesn't seem to be supported by Php/PmWiki?


* Specification of a URI

	http://www.ietf.org/rfc/rfc2396.txt

  Section 2.2. explains that '&' is

	called "reserved", since their usage within the URI component is
	limited to their reserved purpose.

   The purpose in this context is of course to separate the different 
   pairs of 'control name'/'control value'.

	http://www.w3.org/TR/html401/interact/forms.html#submit-format

/Christian

-- 
Christian Ridderstr?m                           http://www.md.kth.se/~chr





More information about the pmwiki-users mailing list