Forum Moderators: open

Message Too Old, No Replies

Clarification of base href

         

Patrick Taylor

10:35 pm on Nov 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The case in point is a website with internal links to page.htm or /page.htm - in other words relative links with no consistency. Also, some pages are HTML and others are XHTML. I was thinking of introducing the use of:


<BASE HREF="http://example.com/" />

... on every page of the site. Can I do this, given the inconsistencies referred to above? Or would I need to rewrite all my links as page.htm? Or... the other way round, if I used:


<BASE HREF="http://example.com" />

together with /page.htm?

The object of the exercise would be to try to reduce the risk of search engines indexing pages incorrectly.

encyclo

2:01 am on Nov 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In general you should use the following:

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

rather than the version without the trailing slash. Both "page.htm" and "/page.htm" will resolve in relation to the root directory of example.com in this case.

The difficulty as you have guessed it with the mix of relative and absolute links when you have pages in subdirectories. One possibility is to alter the base href to take into account the actual directory the page is in. For example if your page is:

http://www.example.com/widgets/page.htm

You could use the base href:

<base href="http://www.example.com[b]/widgets/[/b]">

(note: the trailing slash is absolutely vital here)

That would mean that a link to "page.htm" would resolve to the age within the widgets directory, whereas "/page.htm" would resolve to the root directory (as you would expect).

Are your pages generated or static? If they are generated then you could make the base href tag automatically use the current working directory. If static, you either have to customize the base href tag for each directory or you will need to switch all your links to being relative to root: ie. "/directory/page.htm".

Patrick Taylor

8:38 am on Nov 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks. I am looking particularly at my WordPress pages, which are dynamically generated, and with a single standard "header" file making it difficult to vary the base href URL. I did in fact give <base href="http://www.example.com/" /> a try a few days ago with no apparent ill effect, and I have again checked my internal links within WordPress and they all seem to begin with a forward slash - including those to images, stylesheet, etc.

So it would appear that I am safe using the above.

Is is true to say that if I use a particular base href and the site functions correctly, that the base href is okay? Or might there be hidden and harmful effects with a wrong base href (even though the site displays and navigates as it should?

tedster

3:44 pm on Nov 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



internal links within WordPress and they all seem to begin with a forward slash

The only potential trouble I've ever known comes with two factors: subdirectories and relative links (those that do not begin with a slash.) So what you describe should be trouble free. And if you can find no broken links while navigating with a browser, then a spider should also be fine.

Maybe run an automated link checker on the site just to be sure there are no broken links.

Patrick Taylor

5:04 pm on Nov 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks for that. All seems well.