2011-08-23 78 views
0

在Apache重写时遇到了一些问题。 我的整个网站都运行在SSL(在线商店)上,除了一个页面(visit_us.php)和谷歌地图API(因为谷歌收取$$$$$的HTTPS访问)。每当这个页面包含不安全的内容(这对任何最终用户听起来都不好)时,这个页面显示一条消息,我实现了一个简单的apache重写规则切换到端口80,它工作正常。apache rewrite woes

RewriteEngine On 

#redirect all http traffic to https, unless visit_us.php is requested 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} !^/visit_us\.php 
RewriteRule ^(.*)$ https://www.myurl.com/$1 [R=301,L] 

#redirect https traffic for visit_us.php to http 
RewriteCond %{SERVER_PORT} 443 
RewriteCond %{REQUEST_URI} ^/visit_us\.php 
RewriteRule ^(.*)$ http://www.myurl.com/$1 [R=301,L] 

然而,在整合Twitter的微件(只能工作在HTTP),我意识到我将不得不社交网络页面添加到工作在端口80 我以为这是简单的列表够了,加上social.php页面,上面的列表中,像这样:

RewriteEngine On 

#redirect all http traffic to https, unless visit_us.php or social.php is requested 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} !^/visit_us\.php 
RewriteCond %{REQUEST_URI} !^/social\.php 
RewriteRule ^(.*)$ https://www.myurl.com/$1 [R=301,L] 

#redirect https traffic for visit_us.php and social.php to http 
RewriteCond %{SERVER_PORT} 443 
RewriteCond %{REQUEST_URI} ^/visit_us\.php 
RewriteCond %{REQUEST_URI} ^/social\.php 
RewriteRule ^(.*)$ http://www.myurl.com/$1 [R=301,L] 

在我的网站,我明确地链接到HTTP,而不是HTTPS。然而,虽然它仍然适用于visit_us.php页面,但social.php页面似乎被忽略,并且请求不断终止在端口443. 我在做什么错误?

+0

Apache questi ons几乎总是偏离这个stackoverflow.com。总是有serverfault或网站管理员stckexchange站点。 –

+0

我会铭记未来,谢谢。 – Stann0rz

回答

2
#redirect https traffic for visit_us.php and social.php to http 
RewriteCond %{SERVER_PORT} 443 
RewriteCond %{REQUEST_URI} ^/visit_us\.php 
RewriteCond %{REQUEST_URI} ^/social\.php 
RewriteRule ^(.*)$ http://www.myurl.com/$1 [R=301,L] 

不能使用默认AND逻辑在这里改写条件 - 它必须是OR逻辑,而不是(读简单的英语你的条件,你会看到破绽)。

两种方法:

1.明确指定OR逻辑应使用:

#redirect https traffic for visit_us.php and social.php to http 
RewriteCond %{SERVER_PORT} 443 
RewriteCond %{REQUEST_URI} ^/visit_us\.php [OR] 
RewriteCond %{REQUEST_URI} ^/social\.php 
RewriteRule ^(.*)$ http://www.myurl.com/$1 [R=301,L] 

2.合并两个重写条件成一个(其中OR逻辑被使用) :

#redirect https traffic for visit_us.php and social.php to http 
RewriteCond %{SERVER_PORT} 443 
RewriteCond %{REQUEST_URI} ^/(visit_us|social)\.php 
RewriteRule ^(.*)$ http://www.myurl.com/$1 [R=301,L] 
+0

啊,没想到AND是默认的运营商,因为visit_us还在工作。但后者似乎更合适,效果很好,谢谢你的提示! – Stann0rz