SitePoint Sponsor

User Tag List

Results 1 to 25 of 25
  1. #1
    SitePoint Zealot samg914's Avatar
    Join Date
    Nov 2009
    Location
    Boston, MA
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Relative vs. Absolute Links

    I have several questions regarding absolute and relative links.

    A) When I post a newly designed website on my testing server I can't use the links to navigate through it, if they are absolute. What is the best solution(s) for this?

    B) What are the pros and cons to having absolute and relative links?


    Thanks in advance,

    Samuel

  2. #2
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,888
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by samg914 View Post
    A) When I post a newly designed website on my testing server I can't use the links to navigate through it, if they are absolute. What is the best solution(s) for this?
    The best solution is to have relative links...

    B) What are the pros and cons to having absolute and relative links?
    I would always use relative links. It is much less hassle, and it enables you to work locally and on a test server without having to change anything when you go 'live'.

    On some occasions, I will use links 'relative to the root', such as referencing images or other resources that are stored centrally rather than in the same folder as the document, but mostly I use the simplest form of relative linking possible.

    The biggest advantage that absolute linking has (IMO) is that if someone downloads a page from your site onto their computer, on-site links will still work. From that point of view, it may be worthwhile making the "home" link an absolute link so that it will work in any context, but to be honest I don't think it's a big issue these days because people generally bookmark pages and link to them rather than downloading them.

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,833
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Relative links should be used for all the links within your site - that way the links will work both on your test server and the live one.

    Absolute links should be used for all links to other sites.

    With that combination your site can be moved anywhere and will still work (as long as the whoole site is moved).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  4. #4
    SitePoint Wizard bronze trophy Black Max's Avatar
    Join Date
    Apr 2007
    Posts
    4,029
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    So here's a related question: what's the skinny on "root-relative" links:

    /directory/page.html
    Craig Grannell's "The Essential Guide to CSS and HTML Web Design" recommends them, but I've read other articles that recommend against them.

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,273
    Mentioned
    60 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Black Max View Post
    ... but I've read other articles that recommend against them.
    o rly?

    root relative links are way more flexible

    especially when you combine them with the BASE tag
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,888
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Black Max View Post
    So here's a related question: what's the skinny on "root-relative" links:

    /directory/page.html

    Craig Grannell's "The Essential Guide to CSS and HTML Web Design" recommends them, but I've read other articles that recommend against them.
    A lot of it depends on how you structure your site.

    If you are linking to fixed resources, eg "/scripts/welcome.js", then a root relative link is probably best, rather than trying to remember or compute how many levels up you need to go before heading into the scripts folder. On the other hand, if you're linking to sibling resources, eg you have the images relevant to a page in the same folder as that page or in a child folder, then root relative links add an extra layer of faff and kerfuffle that you don't need to bother with.

    There's no reason why you can't have relative and root-relative links mixed within your site, depending on what works best in each case.

  7. #7
    Non-Member
    Join Date
    Mar 2005
    Location
    Bangkok
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    Relative links should be used for all the links within your site - that way the links will work both on your test server and the live one.

    Absolute links should be used for all links to other sites.
    I've heard that absolute links are better for SEO.

    For example, instead of your home link being "index.php" it ought to be "http://www.mysite.com".

    Google "seo company" and take a look at the link structure used by the major companies.

  8. #8
    SitePoint Wizard bronze trophy Black Max's Avatar
    Join Date
    Apr 2007
    Posts
    4,029
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by andrew-bkk View Post
    I've heard that absolute links are better for SEO.
    I'll sacrifice the chickens at the dark of the moon and get back to you.

    No offense intended, but I just have this visceral hatred of all these SEO rumors. If you create a well-crafted, standards-compliant site with excellent content, there's no need to propitiate the Google gods, your site will be fine without you losing your lunch over your bounce rate and all the other SEO sludge that comes around. You could be right that you might get some miniscule SEO benefit from absolute links, but I doubt those few extra hits are worth the time and effort you'll need to expend on changing the links when you port your site to another domain, or tweak your site structure, or polish up your navigation, or....

  9. #9
    Non-Member
    Join Date
    Mar 2005
    Location
    Bangkok
    Posts
    105
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Black Max View Post
    You could be right that you might get some miniscule SEO benefit from absolute links, but I doubt those few extra hits are worth the time and effort you'll need to expend on changing the links when you port your site to another domain, or tweak your site structure, or polish up your navigation, or....
    Actually, I heard that only the home link needs to be absolute. The internal stuff can remain relative.

    I heard this from an Australian guy who had his own SEO business. He seemed to feel it was quite important.

    I agree though that most of these SEO rumours are dire.

  10. #10
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,888
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by andrew-bkk View Post
    I've heard that absolute links are better for SEO.

    For example, instead of your home link being "index.php" it ought to be "http://www.mysite.com".
    Absolute nonsense. The only thing I would do differently is that (for SEO purposes at least), the home link should just be "/" with no filename - this is so that search engines don't end up indexing "/" and "/index.php", with the risk that your link juice is split between the two.

    All search engines care about is where the link takes them, they really don't care whether it's an absolute or relative link, just so long as it takes them to the right place.

    As Max says, dumb rumours like this surround SEO and there are snake oil salesmen galore ... but the truth is, there is no silver bullet.

    When you come across a rumour like this, ask yourself "Would it make sense for Google to do this?". Google is in the business of giving people the best websites to match the search query they put in. End of. They are not going to put arbitrary barriers in the way of that, like preferring absolute links. Would giving preference to sites with absolute links give more relevant search results? No. Is Google going to do that? No. Will using absolute linkshelp Google to spider and index your site? No. Is there any SEO benefit from using absolute links? I'll let you answer that, and see if you've spotted the pattern

  11. #11
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    root relative links are way more flexible

    especially when you combine them with the BASE tag
    I agree with r937 here, and if you use server-side languages it will work both locally and hosted when you use the server name in the href. In asp I use
    Code:
    <base href="http://<&#37;=request.serverVariables("SERVER_NAME")%>">
    Which I don't have to change when uploading
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  12. #12
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would always use relative links. It is much less hassle, and it enables you to work locally and on a test server without having to change anything when you go 'live'.

  13. #13
    SitePoint Member
    Join Date
    Jun 2010
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use base tage for the absolute part of the address and than use relative path. relative path is good to use because if you need to change domain or directory you dont need to change the links , but the <base> tag.

  14. #14
    Mouse catcher silver trophy Stevie D's Avatar
    Join Date
    Mar 2006
    Location
    Yorkshire, UK
    Posts
    5,888
    Mentioned
    122 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by drsim View Post
    use base tage for the absolute part of the address and than use relative path. relative path is good to use because if you need to change domain or directory you dont need to change the links , but the <base> tag.
    The <base> element is only useful if it points to something other than the path to the current file. If it's pointing to the location of the file you're in, it's unnecessary and redundant - then it's safer to leave it out, so you don't have to remember to change it later.

  15. #15
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    I have a friend/client with a Magento site and because his SEO guy said links had to be absolute, each and every link on his entire site is very, very long. It's sad, because there are so many links (a link to every single product on every single page) that I'm pretty sure it is noticeable by dialup users. Not to mention, dealing with his HTML is extra maintenance.

  16. #16
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,833
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Stomme poes View Post
    I have a friend/client with a Magento site and because his SEO guy said links had to be absolute, each and every link on his entire site is very, very long. It's sad, because there are so many links (a link to every single product on every single page) that I'm pretty sure it is noticeable by dialup users. Not to mention, dealing with his HTML is extra maintenance.
    Must be losing a lot of visitors as a result of that. Perhaps they should consider hiring an SEO expert to fix up their site. Obviously all the absolute links have to go as a first step. The extra time it takes for the domain lookups and the extra length of the page are far bigger SEO penalties than the minute extra benefit gained from the repetition of any keywords in the domain name (and with too many repetitions of the same keywords there's also the keyword spamming penalty to consider).
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  17. #17
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    Quote Originally Posted by felgall
    Perhaps they should consider hiring an SEO expert to fix up their site.
    No, that was his mistake. He hired an SEO expert.

  18. #18
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,833
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Stomme poes View Post
    No, that was his mistake. He hired an SEO expert.
    No, his mistake was in hiring someone who claimed to be an SEO expert. If he'd hired someone who actually was an SEO expert then they wouldn't have been given such inappropriate and completely wrong advice.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  19. #19
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    Lawlz. Another client of mine went to a marketing and SEO company (formed by one of the former directors of a large telecom) where, on their own website, they have nonexistent tags and Javascript and multiple h1's everywhere.

    How's anyone going to know who's an expert and who claims to be an expert? Which is why my client's mistake was getting an SEO expert in the first place. They may exist, somewhere. Nobody who thinks they need one knows where to find one.

  20. #20
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,833
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Stomme poes View Post
    How's anyone going to know who's an expert and who claims to be an expert?
    I think rule one when it comes to SEO experts is that anyone who claims to be an SEO expert isn't one.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  21. #21
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    I've spent five minutes reading an article on "SEO" ....well I am now qualified as an "SEO" expert. Hurrrah! [That is my impression of pretty much all "SEO" experts.]
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  22. #22
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    Logic, can I hire you as my SEO expert? I need some higher rankings FAST : )

  23. #23
    SitePoint Wizard bronze trophy Black Max's Avatar
    Join Date
    Apr 2007
    Posts
    4,029
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    cn i get som bklinks pls kthx, & moar llamas pls too k

    SEO blither plus text-talk plus NPD equals gibberishification....

  24. #24
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,278
    Mentioned
    50 Post(s)
    Tagged
    2 Thread(s)
    Off Topic:

    Oooh ooh yes llamas!
    Code:
    if (!L33tSEO()) {
      return ((Llama) LlamaFarm.getInstance())++;
    }
    Yeah it's a mangled version of that m0aRcoWbell Java code swirling about... just ordered the Tshirt : )

  25. #25
    SitePoint Wizard bronze trophy Black Max's Avatar
    Join Date
    Apr 2007
    Posts
    4,029
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    Off Topic:

    Llamas AND cowbells! It just doesn't get any better....


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •