?
Solved

Relative vs. absolute links in web pages

Posted on 2014-02-20
4
Medium Priority
?
270 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 84

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 44

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 22

Author Comment

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

Featured Post

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

649 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