Forum Moderators: open

Message Too Old, No Replies

Do we need to use a <base> tag if we have already a 301 in place?

         

iaaa

10:34 am on Apr 22, 2006 (gmt 0)

10+ Year Member



Hi,

I was wondering about that. I have a 301 in place, redirecting from example.com -> www.example.com

Is there any point of using:

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

I am not sure even if those two are related; I was just thinking in terms of making navigation easier for robots, as I use relative linking in the format of "/category/file.html" .

Regards

tedster

4:27 pm on Apr 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, there is value in using the <base> tag. For example, it can correct a relative url on the page, even if the user agent only records it in some list somewhere and doesn't immediately GET the new page. It can also be a help to you when someone "borrows" your entire page.

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

Be sure to use the <base> tag correctly. For those who use root-relative paths (urls that always begin with /) this "should be" OK. However, if you use page-relative urls, then the <base href=""> should contain, at a minimum, every directory and sub-directory in the path. Ideally, you would use the full, preferred url for the page itself.

In fact, this is the best practice. It hands the visiting user agent your preferred version of the document's url -- no matter how it may actually have come to the page.

Page Fragment Troubles
(name or id anchors - fragment identifiers using "#")
Browsers today get this one WRONG if you just use the domain as the base href. The W3C expects a fragment identifier always to go to a "name" or "id" on the same page, but this will only happen if you use the page's full url as the <base href=""> reference.

See the Base Element Test Page [w3.org] from the W3C website.

iaaa

5:13 pm on Apr 22, 2006 (gmt 0)

10+ Year Member



Thanks Tedster,

That was indeed illuminating to me. In fact I do use root-relative paths in order to keep away from problems that may arise if "./" and "../." were in place. I.e. if I want to link to 'whatever.html' of 'subcat1' directory (example urls below) I d use "/category1/subcat1/whatever.html" That page at W3C 'Base Element Test Page' was quite confusing. Did that mean that if I use <base> I cannot make reference links on the same page such as the popular "go to top" and "go to middle" (some of my pages would benefit from them to relief scrolling). Or is it just affect deeplinking?

Regarding the correct use of the <base>, if the website is in the format:

www.example.com (root)
www.example.com/category1/whatever.html
www.example.com/category2/whatever.html
www.example.com/category1/subcat1/whatever.html
www.example.com/category1/subcat2/whatever.html

the <base> for each of these pages respectively would be pointing at:

www.example.com
www.example.com/category1
www.example.com/category2
www.example.com/category1/subcat1
www.example.com/category1/subcat2

which is the containing directory of each page (without the trailing slash - or with the slash!?).

Cheers.

tedster

5:35 pm on Apr 22, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



With the trailing slash is best -- it avoids the extra redirect on the server side. You can get into a situation where there is a double redirect for a link somewhere, and then the PR transfer, anchor text influence, etc, may be ignored.

Best practice is to use the full url of the page itself as the base href. Truncating at the directory still allows some funny stuff to sneak in.

iaaa

6:21 pm on Apr 22, 2006 (gmt 0)

10+ Year Member



Cheers Tedster,

Got that sorted. I am currently looking how to apply content negotiation. I am trying to find a resource that states how to configure the web server to handle certain file types so that I can refer to them without the extension. Its a nightmare that; every guide and tutorial I ve seen over the last few days, base their examples on dynamic content or with serving two different languages of the same content. Mine is static and the only files I use are .html, .png, .jpg, .gif, .rss, .txt. There must be a simple way to do that with .htaccess. All I want is to call files without the extension so that I have more tidy URIs.

Thanks for your help.

Regards.

ashis06

10:01 am on Feb 12, 2008 (gmt 0)

10+ Year Member



HI,

should i add this tag into all pages or only index(home) page?

penders

11:48 am on Feb 12, 2008 (gmt 0)

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



should i add this tag into all pages or only index(home) page?

A website is essentially a collection of individual/unrelated pages. So on that basis the <base> tag (or any tag) is added per page - any page you wish the <base> tag to be applied.