开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜