首页 > 解决方案 > 如何在html中设置根链接?

问题描述

我在根目录中有footer.html 文件,即example.com/default/,我将此文件加载到其他html 文件中。现在问题出在 footer.html 中有类似的 href

<li><a href="https://example.com/default/contact">Contact</a></li>

当它呈现在其他文件中时,就像它呈现为页脚一样

https://example.com/default/page1/index.html

联系人href变成

https://example.com/default/page1/contact

如何在 footer.html 中设置根目录,以便在 page1/index.html 中呈现时,联系人 href 应该像

https://example.com/default/contact

不喜欢

https://example.com/default/page1/contact

以下是 Footer.html 中的链接,此文件位于(目录:https ://surgehost.com/template/footer.html )

<ul class="list-unstyled">
              <li><a href="https://surgehost.co.uk/template/web-hosting">Web Hosting</a></li>
              <li><a href="https://surgehost.co.uk/template/domain-names">Search for a Domain</a></li>
              <li><a href="https://surgehost.co.uk/template/vps">Virtual Private Servers</a></li>
              <li><a href="https://surgehost.co.uk/template/ssl-certificates">SSL Certificates</a></li>
            </ul>

index.html(目录:https ://surgehost.co.uk/template/vps )

<div id="footer"></div>
<script>
    $(function(){
        $("#footer").load("/template/footer.html");
    });

</script>

现在在 vps/index.html 中,当我单击网络托管时,它会将我重定向到

https://surgehost.co.uk/template/vps/web-hosting

但它应该重定向到我提供的硬编码的完整 URL

https://surgehost.co.uk/template/web-hosting

可能是什么原因?请帮忙。我在这个问题上失去了理智。

标签: html

解决方案


使用<a href="/default/contact">Contact</a>. 这将使用从 root 开始的完整路径,being https://example.com,导致https://example.com/default/contact


推荐阅读