2014-06-13 291 views
0

我想将旧的https页面重定向到新的http页面。我试过这个规则几次,但它不起作用:将单个https页面重定向到另一个http页面

RewriteRule ^https://www.mydomain.com/tc/page.html$ http://www.mydomain.com/index.php [L,R=301] 

任何一个知道什么是问题?

回答

0

你重写规则是这样的:

RewriteRule ^https://www.mydomain.com/tc/page.html$ http://www.mydomain.com/index.php [L,R=301] 

它改成这样:

RewriteRule ^tc/page.html$ http://www.mydomain.com/index.php [L,R=301] 

同时确保RewriteEngine设置为On &有一个https检查,以及:

RewriteEngine On 
RewriteCond %{HTTPS} on 
RewriteRule ^tc/page.html$ http://www.mydomain.com/index.php [L,R=301] 

问题是wh带你尝试匹配https://www.mydomain.com/tc/page.html它会尝试在像这样的具体路径的顶部与域:

https://www.mydomain.com/https://www.mydomain.com/tc/page.html 

这是不正确,因为这将永远存在。另外,虽然我并不清楚你的桌面环境是什么,但在测试这类东西时,通常最好不要相信浏览器。我强烈建议使用curl-I选项来返回请求的标题,以便完全测试它,而不会像这样在浏览器怪癖中缓存&。

例如,我测试了这个规则我本地的Mac OS X MAMP设置是这样的:

curl -I http://localhost:8888/tc/page.html 

并返回curl -I输出为:

HTTP/1.1 301 Moved Permanently 
Date: Fri, 13 Jun 2014 02:08:53 GMT 
Server: Apache/2.2.23 (Unix) mod_ssl/2.2.23 OpenSSL/0.9.8y DAV/2 PHP/5.4.10 
Location: http://www.mydomain.com/index.php 
Content-Type: text/html; charset=iso-8859-1 

Location:场证实了这一规则的作品如预期。

+1

我相信你需要在你的规则中添加'RewriteCond%{HTTPS}'条件。 – anubhava

+0

@anubhava注意。谢谢! – JakeGould

+1

+1这个答案应该可以正常工作 – anubhava

相关问题