Solved

Relative vs. absolute links in web pages

Posted on 2014-02-20
4
262 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
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 125 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 125 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 20

Author Comment

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Accessibility and Usability are two concepts that seem to be closely related.  But, too many people seem to have a distorted perception of them. During last five years, those two words have come to the day-to-day work of almost every web develope…
An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

864 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now