【问题标题】:Allow access only for robot.txt via http, others at https仅允许通过 http 访问 robots.txt,其他通过 https 访问
【发布时间】:2015-03-21 08:47:36
【问题描述】:

我想在 https 上重定向我的所有流量,只有 robots.txt 应该可以通过 http 访问。

是否可以为 robots.txt 文件创建异常?

我的 .htaccess 文件:

RewriteEngine On
RewriteCond %{SERVER_PORT}   !^443$
RewriteRule  (.*)  https://%{HTTP_HOST}/$1   [R=301]

【问题讨论】:

  • 注意必须命名为robots.txt,而不是robot.txt
  • 您能解释一下为什么要这样做吗? robots.txt 中的规则是否适用于您的 HTTPS 站点?
  • 如果客户在没有 https 的情况下访问页面,我会自动重定向他,但谷歌需要没有 https 的 robots.txt,谷歌管理工具中存在访问错误

标签: .htaccess http redirect https robots.txt


【解决方案1】:

是的,你可以这样做:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteRule !^robots\.txt$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,NC,R=301,L]

确保这是根 .htaccess 中的第一条规则。

【讨论】:

    猜你喜欢
    • 2016-08-06
    • 2019-07-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多