【问题标题】:RewriteRule Apache Directives in .htaccess not working.htaccess 中的 RewriteRule Apache 指令不起作用
【发布时间】:2014-09-03 15:51:36
【问题描述】:

我的 PHP wordpress 应用程序的 .htaccess 文件位于 clone-directory/php/ 中,我可以说它已被 OpenShift 服务器识别。但是某些 RewriteRules 和 RewriteCond 似乎不起作用。由于爬虫可以通过 http 和 https 访问该应用程序,因此我正在尝试为 ssl 和 http 连接创建单独的 robots.txt。

我一直在研究几个不同的代码,但没有一个有效。其中一些如下...

1

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^robots.txt$ robots-https.txt [L]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

2

<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymlinks 
RewriteCond %{SERVER_PORT} ^443$ 
RewriteRule ^robots.txt$ robots-https.txt [L]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

3

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^robots.txt$ robots-https.txt [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

4

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} ^on$ [NC]
RewriteRule ^robots.txt$ robots-https.txt [L]

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

5

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

RewriteCond %{HTTP:X-Forwarded-Proto} =https
RewriteRule ^robots.txt$ robots-https.txt [L]

当我访问https://reversiblean-reversiblean.rhcloud.com/robots.txt 时,网址不会重定向。 URL 始终相同。

【问题讨论】:

    标签: wordpress apache .htaccess https openshift


    【解决方案1】:

    保持这样:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{HTTPS} on [OR]
    RewriteCond %{HTTP:X-Forwarded-Proto} https [OR]
    RewriteCond %{SERVER_PORT} =443
    RewriteRule ^robots\.txt$ /robots-https.txt [L,R,NC]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    

    【讨论】:

      【解决方案2】:

      确保 robots.txt 和第二个 robots.txt 存在于 repo 的 php 目录中。除非 OpenShift 会将其指向默认的 robots.txt,但我不确定该文件的存储位置。我期待 url 改变,但只有 robots.txt 的内容会根据 http 协议改变。

      我不敢相信我已经花了将近一半的时间在这上面。 :)

      如果其他人遇到问题或想知道 Google 的重复内容问题,以下是我的 .htaccess 现在的样子...

      <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      
      RewriteCond %{HTTP:X-Forwarded-Proto} https
      RewriteRule ^robots.txt$ robots-ssl.txt [L]
      
      RewriteRule ^index\.php$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /index.php [L]
      </IfModule>
      

      【讨论】:

        猜你喜欢
        • 2012-12-30
        • 1970-01-01
        • 2017-11-27
        • 2022-01-23
        • 1970-01-01
        • 2013-01-20
        • 1970-01-01
        • 2012-12-10
        相关资源
        最近更新 更多