Welcome to WebmasterWorld Guest from

Forum Moderators: incrediBILL

Message Too Old, No Replies

The <base> element and how to use it effectively



3:17 pm on Aug 3, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

System: The following messages were split from the Metatag Labyrinth thread [webmasterworld.com]

<base href="http://www.example.com/">

to establish the base url of the site.

Our site uses internal a href links like this:

<a href="/page1.htm">

Rather than the full url.

We used to use a base ref on each page that was:

<base href="http://www.example.com/">

But recently decided to specify the exact url of each page in the base ref:

<base href="http://www.example.com/page2.htm">

So every page has a different base ref url.

Is this okay or will it cause confusion or conflict to some bots?

I did have a look at WebmasterWorld but couldn't get a definite answer.

If it's wrong we'll change it back.

[edited by: encyclo at 11:24 pm (utc) on Aug. 5, 2007]


6:57 am on Aug 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

In part answer to my own question:

I used W3c's own link checker and it found no broken links, handling the base ref properly, as did another online site-wide link checker, however, I just tried an online site analysis tool at random.
It is on G's first page of results.

And it (falsely) claimed all my internal links were broken.

They work fine, but the analysis tool simply added the internal link to the base ref url thus:


Resulting in a 404.

So there's one clear example of a bot getting confused by this. The first one I've noticed.

NB: I use the full page url in the base href and root-relative internal links.

PS: thebear: Using CSS and ditching tables dramatically improved our load times. (Just scored 10 out 10). Also we lifted the page text to the top of the html file so it gets looked at first by the bots.

But I understand what you mean about multiple external css files and overdoing the styling.

You clearly have more confidence in SEs than I do. :)


11:57 pm on Aug 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Confidence in SE's you must be joking.

However if they get that part totally wrong they would be out of business very quickly.

Besides html element striping is fairly straight forward.

Like I said after many tens of thousands of pages with many links I haven't seen any fallout.

I also would not add to the complexity of what has to be done to determine what that href actually points to.

The other thing is that the bot doesn't do the indexing or ranking.


4:01 am on Aug 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

I have used full base href on multiple client sites for several years along with full urls in every thing except images. I did this for the purpose of protecting them from scrapers/hijackers and I haven't had a problem since I set it up.

I don't use full urls on images just in case someone puts the page in a frame (even though I have a pop out of frames script on every page) so if the page does manage to get copied the images won't work but the URLS to my site will work.

JAB Creations

11:57 pm on Aug 12, 2007 (gmt 0)

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

I'm not really following the thread but for those who would to minimize changing things between the test and live environments they can feel free to use this PHP script I created. This will allow you to use the base element in conjunction with your scripts and stylesheets from localhost, your/an IP, and your domain name.

Being in a test environment I default to localhost, you could change it to your local IP of course.

The second part matches your domain name (doesn't need to be exactly your domain name).

The third part assumes you're running your local environment but are showing your test work to a friend via your IP address.

Also if you're using HTML instead of XHTML you will want to remove the trailing slash on the second to last line.

Hope some people find this handy! :)

- John

if ($_SERVER['HTTP_HOST'] == "localhost")
$path = 'http://localhost/this_projects_path/';
else if ($_SERVER['HTTP_HOST'] == "yoursite")
$path = 'http://www.yoursite.com/';
$path = 'http://'.$_SERVER['SERVER_ADDR'].'/this_projects_path/';

echo '<base href="';
echo $path;
echo '" />' . "\n";


10:21 pm on Aug 13, 2007 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Very useful thanks!
This 35 message thread spans 2 pages: 35

Featured Threads

Hot Threads This Week

Hot Threads This Month