【问题标题】:mod_rewrite http/https for robots.txtmod_rewrite http/https for robots.txt
【发布时间】:2015-01-14 10:12:22
【问题描述】:

有没有办法重写 robots.txt 的路径/文件名?

在我的 docroot 中,我放置了 robots.txtrobots_ssl.txt。现在我想“重定向”机器人,具体取决于他实际访问的站点。我在.htaccess 中制定了一条规则,内容如下:

RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^robots\.txt$ robots_ssl.txt [L]

为了查看差异,我在两个文件的顶部添加了注释。当我调用https://example.com/robots.txt 时,它应该显示一个带有注释的 txt 文件:

https 的 robots.txt

否则,如果是http:

http 的 robots.txt

任何想法如何解决这个问题?我的 RewriteCond 错了吗?

【问题讨论】:

    标签: .htaccess mod-rewrite robots.txt


    【解决方案1】:

    您可以使用此规则来提供特定于 SSL 的 robots.txt

    RewriteEngine On
    
    RewriteCond %{HTTPS} on
    RewriteRule ^robots\.txt$ robots_ssl.txt [L,NC]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-20
      • 2015-03-12
      • 2013-07-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多