重写规则Apache指令在.htaccess不工作 [英] RewriteRule Apache Directives in .htaccess not working

查看:190
本文介绍了重写规则Apache指令在.htaccess不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的PHP字preSS应用我的.htaccess文件是在克隆目录/ PHP / ,我可以说,它是由OpenShift服务器识别。但是,一些规则集和的RewriteCond的似乎并没有工作。由于该应用程序是通过HTTP和HTTPS通过爬虫访问,​​我想创造SSL和HTTP连接单独的robots.txt。

My .htaccess file for my PHP wordpress app is in clone-directory/php/ and I could say that it was recognized by the OpenShift server. But some of the RewriteRules and RewriteCond doesn't seem to work. Since the app is accessible by both http and https by crawlers, I'm trying to create separate robots.txt for ssl and http connections.

我已经研究了几个小时几个不同的codeS,但他们都不工作。其中一些如下...

I've been researching hours and hours with several different codes but none of them work. Some of them are as follows ...

<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是始终不变的。

When I visit https://reversiblean-reversiblean.rhcloud.com/robots.txt, the url won't redirect. URL is always the same.

推荐答案

确认robots.txt的第二robots.txt的存在于回购的PHP目录。 Unlesss OpenShift将它指向一个默认的robots.txt,但我不知道在哪里的文件存储。我期待的URL改变,但robots.txt的只有内容将根据http协议改变。

Make sure the robots.txt and the second robots.txt exist in the repo's php directory. Unlesss OpenShift will point it to a default robots.txt, though I'm not sure where that file is stored. I was expecting for the url to change, but only the contents of the robots.txt would change according to the http protocol.

我无法相信我已经花了我一天几乎有一半在此。 :)

I can't believe I've spent almost half of my day on this. : )

在万一别人遇到了麻烦或想了解一下谷歌的重复内容的问题,以下是我的的.htaccess 现在看起来...

In case anyone else was having trouble or wondering about Google's duplicate content issue, here's how my .htaccess looks now ...

<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>

这篇关于重写规则Apache指令在.htaccess不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆