Forum Moderators: open
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
<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.
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.
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.
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.