• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

Relative vs. absolute links in web pages

I am working with a web site designer for a client and have run into an issue of how internal links in a web page should be constructed.  I have always subscribed to the idea that all internal (same base URL) links on a site should be relative (no //www.mysite.com at the beginning) for a whole variety of reasons.  An obvious one is that it makes the site much easier to move to another location (e.g. put it in //www.mysite.com/development or on a local computer for a new version of the site while testing and evaluating).

As a "reality check" I stated viewing the code of existing sites and found that most (of my very small survey) use absolute addressing.  This surprised me.

Is there an advantage to the absolute addressing that I am missing?

I'm wondering if these sites were generated by code rather than by a human directly in which case they can be regenerated with the new base URL if they need to be moved.

Any good insight on this would be appreciated.
0
CompProbSolv
Asked:
CompProbSolv
2 Solutions
 
GaryCommented:
Are we talking about this
//www.mysite.com

or this
/mypage.html

The first one is to accommodate moving between http and https easily without any security warnings being issued because you are serving and http linked resource on https whilst still maintaining a full domain url.
The second one is easier to maintain and still gives you relative links regardless of the protocol

Removing //www.mysite.com from all links saves you a few bytes in bandwidth and is not really needed at all.

What you are seeing in other sites maybe a server side built url
You would still need the full domain and protocol if you wanted links on SSL pages to link to the non SSL page.   This is usually done with server side code to determine if to add the full url.
0
 
Dave BaldwinFixer of ProblemsCommented:
I think you need to make your own rules on this.  Even though I almost never move a site, I usually use 'relative' links.  One exception to that is when you have to go from insecure 'http' to secure 'https' because you can't use 'https' without the full link that needs to follow it.

I think you're right about some of the sites being generated by code.  Wordpress sites seem to almost always have absolute links.
0
 
Chris StanyonCommented:
Do whatever is the easiest. If you're manually creating all your links, use relative, otherwise you're hard-coding in a URL (be careful of how you use an opening /)

If your pages are generated dynamically, then you'll either be forced into a decision by a particular framework, or you'll have the option. Setting a base_url in one place may be all that's needed to change all links.

Personally I prefer relative when hand coding (easy to move from server to server, and short to type), and I tend to go with whatever when creating a site that's dynamically built - some systems create relative and others create absolute!
0
 
CompProbSolvAuthor Commented:
Thanks to all for the responses.  This is very helpful.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now