【问题标题】:Cannot access web pages using crawlers after removing index.php from URL从 URL 中删除 index.php 后无法使用爬虫访问网页
【发布时间】: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


【解决方案1】:

使用常规浏览器,您也会收到 403 错误。显示网站的原因如下:

基本身份验证将始终返回 403 错误。在大多数服务器上,ErrorDocument 403 的全局规则的定义类似于 403.html。如果触发 403 错误,服务器将在内部查找错误文档 403.html。该文档不存在并且您的 RewriteRule 匹配并且服务器返回呈现的 index.php 页面。这就是您看到网页的原因,即使它返回了 403 错误。更复杂的是,由于不存在 403.html 站点,因此通过查找 403.html 站点会触发 404(未找到页面)。这就是全局定义的 ErrorDocuments 的问题。错误 500 会触发 404 错误,因为定义了 500.html。

尝试在您的 .htaccess 中定义一个 ErrorDocument 处理,您会看到不同之处。

ErrorDocument 403 "Access denied"

如果触发错误 403,此规则将打印错误消息并停止 index.php 的呈现

【讨论】:

    猜你喜欢
    • 2010-12-10
    • 1970-01-01
    • 2013-08-09
    • 2012-12-27
    • 1970-01-01
    • 1970-01-01
    • 2010-10-28
    • 2018-02-09
    • 1970-01-01
    相关资源
    最近更新 更多