TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

7 pointsby ez77over 14 years ago
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!

4 comments

colandermanover 14 years ago
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.
pzxcover 14 years ago
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.
评论 #1892141 未加载
wusterover 14 years ago
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.
preekover 14 years ago
#3 will be best if the domain name ever changes. It happened to me three times and #3 kept my head over the waterline.
评论 #1892146 未加载