.htaccess中的RewriteRule Apache指令无法正常工作

时间:2014-07-13 15:55:46

标签: wordpress apache .htaccess https openshift

我的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时,该网址不会重定向。网址始终相同。

2 个答案:

答案 0 :(得分:0)

保持这样:

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]

答案 1 :(得分:0)

确保robo.txt和第二个robots.txt存在于repo的php目录中。除非OpenShift将其指向默认的robots.txt,但我不确定该文件的存储位置。我期待更改网址,但只有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>