页面上的相对链接,不带斜杠 [英] Relative links on pages without trailing slash
问题描述
在URL上没有结尾斜杠的页面上,有什么方法可以使用将页面保留在url中的相对链接?
On pages that has no trailing slashes in their URL, is there any way to use relative links that will keep the page in the url?
例如,链接
a href="content"
在页面上
http://www.domain.com/page/
将链接到:
http://www.domain.com/page/content
但页面上的链接相同:(请注意斜杠的缺失)
But the same link on the page: (notice the missing slash)
http://www.domain.com/page
将链接到:
http://www.domain.com/content
由于我的网站没有斜杠(第二个示例),所以我不能使用相对链接,而必须使用完整路径( a href ="/page/content"
).
Since my website has no trailing slash (second example), I can't use relative links and must use the full path (a href="/page/content"
).
推荐答案
除了首先在链接中包含尾部斜杠,或者从缺少尾部斜杠的路径重定向之外,还可以将基本标记设置为始终包含尾部斜杠和当前路径.
Other than including a trailing slash in the link in the first place, or redirecting from paths missing a trailing slash, you may also set the base tag such that it always includes a trailing slash and the current path.
<head>
<base href="/page/" target="_self">
</head>
然后,只要浏览器支持,相对链接应该可以正常工作.也有可能完全限定路径.您可能无法使用javascript动态设置.
Then relative links should work as anticipated as long as the browser supports this. It is also possible to fully qualify the path. You may not be able to set this dynamically with javascript.
这篇关于页面上的相对链接,不带斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!