Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should we use <base href="" />?

I always send all my requests to PHP via mod_rewrite and route using PHP. So all my links are absolute, i.e. /about/something.

I usually write my links like so...

<a href="<?php echo BASE; ?>">home</a>

Where BASE generally translates to / or could be different depending on the base URL.

I remember giving <base href="<?php echo BASE; ?>" /> a go before, but I can't remember why I stopped using it (I think it was giving me headaches).

Are there problems with using this element?

like image 812
alex Avatar asked Dec 06 '10 00:12

alex


People also ask

What is BASE HREF />?

The href attribute specifies the base URL for all relative URLs on a page.

Is Base tag necessary?

No problem. But without the base tag, all of your relative links will break. URL rewrites are often necessary, because tweaking them can help your site's architecture and search engine visibility.

What is the use of base href in angular?

The base href is the URL prefix that should be preserved when generating and recognizing URLs.

Why do we use base tag in HTML?

Definition and Usage The <base> tag specifies the base URL and/or target for all relative URLs in a document. The <base> tag must have either an href or a target attribute present, or both. There can only be one single <base> element in a document, and it must be inside the <head> element.


1 Answers

The href of the base element had, in HTML 4.01, to be an absolute URI. See http://www.w3.org/TR/html4/struct/links.html#h-12.4.

Although some browsers are less strict I believe, I don't think all browsers are consistent in this, so <base href="/"> probably won't work cross-browser.

like image 145
Alohci Avatar answered Nov 08 '22 16:11

Alohci