html - 如何在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
可能是什么原因?请帮忙。我在这个问题上失去了理智。
解决方案
使用<a href="/default/contact">Contact</a>
. 这将使用从 root 开始的完整路径,being https://example.com
,导致https://example.com/default/contact
推荐阅读
- html - CSS - 将样式放在嵌套在元素中的输入上?
- apache-spark - 如何取消使用广播连接广播的表?
- c - 是否有 gcc 选项来解决这个与位域相关的 C 问题?
- fpdf - 如何在 FPDF 的 ISO-8859-1 或 ISO-8859-15 中调用 iconv
- opencv - 如何用 4 个像素扩展特定的颜色斑点?
- kubernetes - Kubernetes Service 连接 TargetPort 而不是 NodePort
- boolean - 关于布尔值作为变量时的应用问题?(单词问题)
- android - 尝试在 Flutter 中使用多个模拟器进行编译时出现 Gradle 错误
- python - 模型性能的皮尔逊相关系数
- json - 在 Swift 5 中使用泛型解析 JSON - 本地文件与 URL