【问题标题】:Why are visitors to my site following absolute links as if they're relative?为什么访问我的网站的访问者会按照绝对链接,就好像他们是相对的一样?
【发布时间】:2016-01-27 11:46:33
【问题描述】:

我网站上的每个页面都有一个导航栏,其中包含一些绝对链接,指向 /archive/atom.xml 等页面。这些出现在像/post/post-title 这样的页面上。

在我的访问日志中,我看到大量对 /post/post-title/archive/post/post-title/atom.xml 等路径的请求。

假设我没有只是在某个地方塞满了链接(即,错过了一个斜线),是否还有其他我可能做错的事情导致一些客户遵循绝对链接,就好像它们是相对的一样?还是只是奇怪的机器人很奇怪?

【问题讨论】:

    标签: html logging hyperlink server


    【解决方案1】:

    带有正斜杠的链接应该加载到您的 Web 项目中具有主域名的任何文件夹中。

    如果你有这样的:

    domain.com/index.php
    domain.com/archive/index.php
    

    并且两个 index.php 文件都有以下内容:

    <a href="/">home</a>
    <a href="/archive">archive</a>
    

    两个文件中的所有链接都是绝对链接,例如:

    <a href="http://domain.com/">home</a>
    <a href="http://domain.com/archive">archive</a>
    

    有两个问题可以产生相对链接:

    1- Having a ./ rather than / in your links. (And that is the best guess)
    2- Bots understands links and love links with "/" not with "http://domain.com/"
    but you might uploaded a file with a ./ link before
    and bots got it and you have it recorded.
    

    此外,相对链接在它们所在的主文件夹中进行处理,例如:

    如下:

    <a href="./another_directory">Other Page</a>
    <a href="./archive">archive</a>
    

    里面:

    domain.com/archive/index.php
    

    将导致:

    <a href="http://domain.com/another_directory">Other Page</a>
    <a href="http://domain.com/archive/archive">archive</a>
    

    【讨论】:

      猜你喜欢
      • 2018-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      相关资源
      最近更新 更多