Html 基本 URL - 如何调用主页链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7093234/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Base URL - How to call the home link
提问by Warface
Here an example of my base URL
这是我的基本 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
我想知道如何在尝试时调用 HOME 链接的基本 URL
<a href="/">Home</a>
It redirect to http://subdomain.domain.com/and not in the /folder/
它重定向到http://subdomain.domain.com/而不是 /folder/
回答by Stefan Steiger
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.
您需要的是应用程序/网站的虚拟目录名称。
这是一个服务器变量,不可能单独在 HTML 中获取它,您需要一些服务器端组件,如 PHP 或 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>
回答by Joseph Marikle
回答by Dr Zeeshan Patoli
Concatenate host name with application path and http/https should give you home URL. code below
将主机名与应用程序路径和 http/https 连接起来应该会给你主页 URL。下面的代码
<a href="https://@[email protected]">Home</a>
回答by dcromley
ADLADS (A Day Late - A Dollar Short)
I got here and can't relate to the dialog.
For me, I find that I wanted
ADLADS(迟到一天 - 一美元空头)
我到了这里,无法与对话联系起来。
对我来说,我发现我想要
<a href="/index.html">Home</a>
Maybe someone else wants this?
也许其他人想要这个?
回答by avetarman
Try not to put anything in your HREF, that is, make an empty HREF.
尽量不要在您的 HREF 中放入任何内容,即创建一个空的 HREF。
This works in latest Firefox, Chrome, Opera, Safari and IE7, IE8, IE9.
这适用于最新的 Firefox、Chrome、Opera、Safari 和 IE7、IE8、IE9。