?
Solved

Relative vs. absolute links in web pages

Posted on 2014-02-20
4
Medium Priority
?
268 Views
Last Modified: 2014-02-25
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
Comment
Question by:CompProbSolv
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39874535
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
 
LVL 83

Accepted Solution

by:
Dave Baldwin earned 500 total points
ID: 39874563
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
 
LVL 43

Assisted Solution

by:Chris Stanyon
Chris Stanyon earned 500 total points
ID: 39874564
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
 
LVL 21

Author Comment

by:CompProbSolv
ID: 39886743
Thanks to all for the responses.  This is very helpful.
0

Featured Post

Linux Academy Android App Now Supports Chromecast

We have some fantastic news for our Android fans. We’re so excited to announce that the Linux Academy Android app is now available with Chromecast support. That’s right – simply download the latest update of the Linux Academy App and start casting your favorite course videos!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question