问题
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?
回答1:
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.
回答2:
I always use base href for the same reason; I use mod_rewrite to make the url into a query string and I don't want to use absolute urls all over the place. So I put one base href at the top. Never had any real issues with it.
回答3:
OpenCart uses it, Magento 1.7+ does not, Drupal 6 does not. I have run into one custom base href implementation in the past and it seems to make maintenance on the project harder, but that's just my opinion.
来源:https://stackoverflow.com/questions/4362258/should-we-use-base-href