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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:06:55  来源:igfitidea点击:

Base URL - How to call the home link

htmlurlbase

提问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

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

看来,如果您要以 开始您的 url(一个取决于基本 url 的 url)/,您需要指定这是来自当前目录级别。因此你的链接应该是

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

回答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。