

Ask HN: Deciding absolute vs. relative URLs, and related issues - ez77

I know this issue is <i>very</i> old news, but frankly I don't know of any thorough discussions or references. (Help!) In short, it would be great to hear the criteria HNers follow when choosing a link style. For example, from "http://example.com/d1/d2/doc.html" to "http://example.com/d1/foo.html" three choices come to mind:<p>1) Absolute URL ("http://example.com/d1/foo.html")<p>2) Relative URL, absolute path ("/d1/foo.html")<p>3) Relative URL, relative path ("../foo.html")<p>Which type of URL do you favor for your intra-site links? Why? Do you try as much as possible to use a single style throughout the site?<p>Further comments and references would be most welcome.<p>Cheers!
======
colanderman
This is going off on a bit of a tangent but I would drop the .html from the
URLs as well. Apache's MultiViews option makes this (and content negotiation)
a breeze, allowing you to keep the extension on your files but drop it from
your URLs. This way, if/when you decide to replace a static page with dynamic
content, your users' bookmarks (and your own intra-site links) won't break.

------
pzxc
I use relative URLs almost exclusively throughout my sites -- the main
exception being anything that ends up or has the potential to end up outside
the site, RSS feeds being the primary example. Relative URLs simply won't work
there, so anything that gets syndicated (through a feed or otherwise) it's
probably best to use absolute URLs.

~~~
ez77
Thank you for your reply. If you don't mind, do you favor relative or absolute
paths? Why?

------
wuster
For option 1, if you're generating pages with templates, just hand off the
domain portion to a util method, so if the domain ever does change, it should
be a one-line change.

------
preek
#3 will be best if the domain name ever changes. It happened to me three times
and #3 kept my head over the waterline.

~~~
ez77
OK, but as long as the directory structure remains the same, #2 would also
work. Why do you prefer #3? (Again, just curious.)

~~~
Jabbles
In case he renames the directory.

~~~
preek
Obvious and true.

