【发布时间】:2011-10-16 04:49:36
【问题描述】:
我已经从网络上显示的应用程序 URL 中删除了 index.php。但后来我有一个奇怪的问题。
我可以使用这样的浏览器访问该网站...http://www.oakquotes.com/quotes/author/etc-etc(请注意缺少 index.php)但是当我尝试使用爬虫访问相同的 URL 时,我会收到禁止的 403 http 错误。
这是 robots.txt 文件:
User-agent: *
Allow:/quotes/topic
Allow:/quotes/author
Disallow:
Sitemap: http://www.oakquotes.com/Sitemap.xml
Sitemap: http://www.oakquotes.com/author_sitemap.xml
Sitemap: http://www.oakquotes.com/topic_sitemap.xml
我认为罪魁祸首是我为从 URL 中删除 index.php 而编写的 .htaccess 规则。这是htaccess的代码:
<IfModule mod_rewrite.c>
# For security reasons, Option followsymlinks cannot be overridden.
# Options +FollowSymlinks
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(index\.php|images|robots\.txt|Sitemap\.xml|topic_sitemap\.xml|author_sitemap\.xml|search\.html|style|js|system|application|quotes/authors|quotes/topic|application/controllers|application/views)
RewriteRule ^(.*)$ ./index.php/$1 [L]
</IfModule>
我错过了一步吗?请在这方面帮助我。谢谢。
【问题讨论】:
-
当您收到 403 错误时,日志会显示什么内容?
-
* 您确定爬虫使用的是 Host 标头吗? * 爬虫之前是否能够访问该站点? * 访问和错误日志说什么? * 爬虫是否提供有关它所获得响应的更多详细信息?
-
是的,它在响应的 http 状态中显示 foorbidden 403...日志没有显示任何特殊的...我认为它与 url 重写的一些问题有关...
-
请为我们测试该理论并发布结果 :) 注释掉 htaccess 文件中的所有重写,删除 robots.txt 文件并尝试爬虫。然后恢复 robots.txt 并尝试。如果仍然有效,请恢复 htaccess 并重试。如果它在那个时候坏了,它可能是 htaccess 文件中的东西,我们可以从那里开始。如果它即使没有 htaccess 文件也没有 robots.txt 也坏了,那么它必须是别的东西。
-
确保您告诉您的爬虫遵循重定向。否则,将永远不会返回默认页面。
标签: php .htaccess codeigniter mod-rewrite url-rewriting