Base URL - How to call the home link

独自空忆成欢 提交于 2020-01-01 04:27:19

问题


Here an example of my base URL

<base href="http://subdomain.domain.com/folder/" />

I would like to know how to call that base URL for the HOME link when I try

<a href="/">Home</a>

It redirect to http://subdomain.domain.com/ and not in the /folder/


回答1:


What you need is the virtual directory name of your application/website.
This is a server variable, and it is not possible to get it in HTML alone, you need some server side component, like PHP or ASP.NET.

If you are in the root directory, you can try a relative link.
So try using a . to indicate "from this folder"

<a href="./">Home</a>


Should your question actually concern the opposite direction, do this:

<a href="../">Home</a>


Or use an absolute link:

<a href="/folder">Home</a>

Or use a canonical link

<a href="http://subdomain.domain.com/folder">Home</a>



回答2:


test case

It appears that if you are going to start your url (a url that depends on a base url that is) with a /, you need to specify that this is from the current directory level. Thus your link should be

<a href="./">Home</a>



回答3:


Try not to put anything in your HREF, that is, make an empty HREF.

This works in latest Firefox, Chrome, Opera, Safari and IE7, IE8, IE9.



来源:https://stackoverflow.com/questions/7093234/base-url-how-to-call-the-home-link

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!