Forum Moderators: open

Message Too Old, No Replies

absolute vs relative paths

what's the difference in an href?

         

createErrorMsg

3:00 pm on Oct 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've always used relative paths in href attributes for on-site links, simply because they are easier to type, easier to edit, easier to read, just, well, easier.

But I'm curious if anyone knows of any other compelling reason NOT to code absolute paths into href attributes for links on-site?

Aside from absolute paths being cumbersome and unnecessary, is it OKAY to use them in href attributes, or does it cause some hidden problems with (a)site navigation, (b)server load, or (c)search engines?

I'm working on a php script that may require absolute hrefs, so it's raised this question that I've never had to think about before...

Thanks for any insight you may have.
cEM

photon

3:41 pm on Oct 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's a link to a discussion in the SEM Research Topics forum: [webmasterworld.com...] As you can tell, the opinions are mixed.

From what I've read around here, just about the only advantage of relative over absolute is the ease of development. You can copy the files from your local machine to the server without needing any changes.

I've been using relative for that reason, but I'm going to switch over to absolute as soon as I figure out how to set up my Powerbook as a server, and figure out the Apache configuration to let me use the full URL locally.

Why? The impression is that absolute URLs do slightly better in the SEs (allegedly GoogleGuy recommends them, but I can't find the post), and it just makes it a little bit harder for a casual/lazy thief to steal my content (Yes, I'm flattering myself :) ). Plus I'm aware of no downsides to using absolutes.

g1smd

8:48 pm on Oct 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>> From what I've read around here, just about the only advantage of relative over absolute is the ease of development. <<

That sounds like you are just browsing your hard-drive from folder to folder.

If you want to use absolute URLs; counted from the root (like /folder/folder/file.html for example) then install Apache, or PHPdev (which includes Apache) then you can browse the local copy of your site by typing http://localhost/ or http://127.0.0.1/ instead.

vkaryl

8:54 pm on Oct 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sometimes you wind up NEEDING to use absolute URLs (when using includes for footers with nav links f'rinstance); if your site structure uses things like fora in "phpBB2" folders; or jalbums in their own folders; or web calendars ditto.... using those includes becomes problematic without absolute links.

Some of us are dumber than others; it took me quite a while to figure this out.... *sigh* I do believe that I'd go farther with all of this had I started 30 years younger!

BjarneDM

11:20 pm on Oct 22, 2004 (gmt 0)

10+ Year Member



photon:
To use full URLs locally you'll have to mess around in /etc/hosts and add an entry like this : 127.0.0.1 test.website.tld

Then, you can set Apache up to serving test.website.tld

No problem with this process. I'm using this to develop about five websites served locally from TiBook using Apache 2 from ServerLogistics and virtual hosting. Works like a charm.

You might be interested in taking a look at my homepage (URL in profile)

StupidScript

11:27 pm on Oct 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



photon, the link went 404 on ya!

Probably mentioned in that thread is the matter of request fulfillment time.

Absolute URLs need to resolve the domain.
Relative URLs do not need to.

For this reason, it is a (very slightly) faster browsing experience for the visitor when you use relative URLs. I would definitely recommend using relative URLs for page content (images, etc.), but you'll have to decide for yourself what to do when linking from one of your pages to another.

I can see the argument for using absolute URLs to gain a SERPS advantage, as when the context of the spidered URL is supported not only by the domain but reinforced by the code it may add extra weight to the links. However this is purely conjecture. I have no idea how the SEs really use such information within a single domain.

Lance

11:57 pm on Oct 22, 2004 (gmt 0)

10+ Year Member



I use relative paths for everything I can because it is easier and more convenient for me to do so. I have two versions of all my sites, usually on two different servers, but maybe not, with names like:

dev.example.tld
and
www.example.tld

I do dev work on the dev version of the site, then deploy to the live version. Using absolute paths makes that almost impossible. For things like external apps then need an absolute path (bb, gallery, blog, etc), I've been using server side variables and it's been working quite well.

For example:
ASP:
http: //<%=Request.ServerVariables("SERVER_NAME")%>/somepage/onmy/site.html

or PHP:
http: //<? echo $_SERVER['SERVER_NAME']?>/somepage/onmy/site.html

vkaryl

12:20 am on Oct 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hooboy.... thanks Lance (I think). I tried to figure something like this out a while back, but failed miserably. I tend to blame that sort of thing on age (it's a convenient dodge....)

So may I try YOUR version, see if I can figure it out? If so, and I can't, y'know I'll be back.... bad penny time....