Alternatives to base tag
I used m开发者_开发知识库ode rewrite on my website
I used the base tag to solve my relative links problem
<base href="/" />
But the problem is absolute link eg. http://www.absolutelinks.com
It changes it to www.mysite.com/http://www.absolutelinks.com
How can i fix this
Base href applies only to the relative URL so if you have got: <a href="http://google.com/">Google</a>
you'll be redirected to Google, not http://mydomain/http://google.com/
. Please post the code of your HTML document.
However using base
isn't the best practice. Much better approach is to use absolute URLs like: src="/styles/main.css"
which always points to mydomain/styles/main.css
.
Don't use <base>
at all, instead have some server-side config and keep a $base variable there - then, when outputting any URL during your HTML generation use {$base}{$restofurl}.
This works well when you have the same code running in development/test/live environments - you just need to change your server-side $base config.
Using PHP/Smarty syntax above but I'm sure you get the idea.
精彩评论