【问题标题】:Which link will a spider use for search listings, the static link or the RewriteRule url?蜘蛛将使用哪个链接来搜索列表,静态链接或 RewriteRule url?
【发布时间】:2013-03-14 18:51:14
【问题描述】:

我是 Apache 重定向的新手,但我已经学会了如何处理 PHP 在我的网站上生成的干净 url,它们运行良好。

我一直在研究这个问题,似乎找不到一个简单直接的答案。

我的问题是爬虫/蜘蛛/机器人会使用 php 在我的网站上显示的链接:example.com\Shoes\Running\Men 还是会使用 RewriteRule url:example.com\subsubcat_lookup.php?c=$1 &s=$2&ss=$3 作为最终会出现在搜索引擎中的那个? (见下面我的 .htaccess)

我还看到了 PT|passthrough 标志,如下例所示:Apache.org - Redirecting and Remapping with mod_rewrite

这是我应该在我的情况下使用的东西吗?

非常感谢您对此问题的任何澄清。

我的 .htaccess 文件:

RewriteEngine on

# do not do anything if already existing file, symbolic link or directory
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ - [L]

# redirect clean url (/category) for processing
RewriteRule ^([^/]+)$ ./cat_lookup.php?c=$1 [L,B]
RewriteRule ^([^/]+)/$ ./cat_lookup.php?c=$1 [L,B]

# redirect clean url (/category/subcategory) for processing
RewriteRule ^([^/]+)/([^/]+)$ ./subcat_lookup.php?c=$1&s=$2 [L,B]
RewriteRule ^([^/]+)/([^/]+)/$ ./subcat_lookup.php?c=$1&s=$2 [L,B]

# redirect clean url (/category/subcategory/subsubcategory) for processing
RewriteRule ^([^/]+)/([^/]+)/([^/]+)$ ./subsubcat_lookup.php?c=$1&s=$2&ss=$3 [L,B]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ ./subsubcat_lookup.php?c=$1&s=$2&ss=$3 [L,B]

【问题讨论】:

    标签: php apache .htaccess mod-rewrite url-rewriting


    【解决方案1】:

    我的问题是爬虫/蜘蛛/机器人会使用 php 在我的网站上显示的链接:example.com\Shoes\Running\Men 还是会使用 RewriteRule url:example.com\subsubcat_lookup.php?c=$1 &s=$2&ss=$3 最终会出现在搜索引擎中吗?

    由于这种重写发生在您的服务器内部(除非您使用显式重定向)——您的蜘蛛是如何知道这些内部 URL 的……?

    蜘蛛会跟随他们在网络上找到的链接——如果您的页面中只有 example.com/Shoes/Running/Men 链接,他们会在哪里找到其他版本?

    无论如何,为了确保“正确”的 URL 被列出 - 添加一个带有 rel=canonicallink 元素,并提供你想在那里使用的 URL。 http://en.wikipedia.org/wiki/Canonical_link_element

    【讨论】:

    • 我会阅读 rel=canonical 并没有意识到这一点。 'other' 版本 (example.com\subsubcat_lookup.php?c=$1&s=$2&ss=$3) 的唯一位置是在我的 .htaccess 中,如上所示,但不清楚蜘蛛是否曾经看到或知道使用没有 R 标志的 RewriteRule 时存在“其他”URL。谢谢。
    【解决方案2】:

    这取决于爬虫的实现。例如,我可以编写一个爬虫来存储原始 URL(不是 .htaccess 使用重写给出的那个),然后未清理的 URL 将存储在我的数据库中,否则将存储干净的 URL。据我所知,像谷歌等爬虫存储干净(重写)的 URL。您可以尝试使用 apache nutch 来查看大多数爬虫的默认行为是什么。

    【讨论】:

    • 所以你是说在我上面的场景中,谷歌最终会在搜索结果中显示的链接是 example.com\subsubcat_lookup.php?c=$1&s=$2&ss=$3 和不是 example.com\Shoes\Running\Men
    • 没有像google这样的成熟爬虫会存储第二个example.com\shoes\running\men。但是也有可以存储其他链接的爬虫。取决于实施。
    • 感谢您的信息。不确定您是否查看了我上面的 .htaccess,但 example.com\shoes\running\men 实际上是第一个链接(在网站上)重写的链接(example.com\subsubcat_lookup.php?c=$1&s=$2 &ss=$3) 是执行实际处理的第二个。
    猜你喜欢
    • 1970-01-01
    • 2010-12-03
    • 1970-01-01
    • 2013-11-30
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 1970-01-01
    • 2020-07-26
    相关资源
    最近更新 更多