1

我是 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]
4

2 回答 2

2

我的问题是爬虫/蜘蛛/机器人会使用我网站上显示的链接 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——添加一个link元素rel=canonical并给出你想在那里使用的 URL。http://en.wikipedia.org/wiki/Canonical_link_element

于 2013-03-15T16:48:17.557 回答
0

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

于 2013-03-15T12:20:14.713 回答