对于几个页面将HTTPS重定向到HTTP,我有一个具体的问题。
我在Zope前面有Apache2。
下面是端口80上我的VirtualHost的配置:
<VirtualHost *:80>
ServerAdmin root@website.com
ServerName website.com
ServerAlias www.website.com
<IfModule mod_rewrite.c>
RewriteEngine On
# www to non www
RewriteCond %{HTTP_HOST} ^www.(.*) [NC]
RewriteRule ^/(.*) http://website.com/$1 [R=301,L]
# HTTP TO HTTPS
RewriteCond %{HTTPS} off
RewriteRule ^/(.*) https://%{HTTP_HOST}%{REQUEST_URI}
</IfModule>
</VirtualHost>在Zope侦听SSL 8443端口之后,我应用了以下iptables规则:
iptables -t nat -A PREROUTING -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 8443所以我的重写规则重定向80到443,iptables重定向443到8443。
在这种情况下,我如何将一个页面(例如"https://website.com/wiki/test")重定向到"http://website.com/wiki/test“。
我试图添加以下规则:
# if https on then turn off
RewriteCond %{HTTPS} on
RewriteRule ^/wiki/test_page.html http://%{HTTP_HOST}%{REQUEST_URI}但不起作用。
与其执行另一条重写规则,我认为对于"/wiki/test_page.html“页,应该更容易防止HTTPS重定向,但我不知道如何实现。
欢迎任何建议,
谢谢
更新1 :
我试过:
# HTTP TO HTTPS except page "/wiki/test_page.html"
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/wiki/test_page.html
RewriteRule ^/(.*) https://%{HTTP_HOST}%{REQUEST_URI}未获成功
更新2 :
我在我的问题上取得了进展。我的临时解决办法是:
RewriteEngine On
# www to non www and HTTP to HTTPS redirection for all website
RewriteCond %{REQUEST_URI} ^/www\. [NC,OR]
RewriteCond %{REQUEST_URI} !^/wiki/test_page\.html [NC]
RewriteRule ^/(.*) https://website.com/$1 [R=301,L]
# rewrite HTTPS to HTTP for test_page.html
#RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/wiki/test_page\.html [NC]
RewriteRule ^/(.*) http://localhost:9674/++vh++http:%{SERVER_NAME}:80/++/$1 [P,L]有了这些规则,除了/wiki/test_page.html页面之外,我可以使用HTTPS链接浏览我的所有网站。为此,我在包含链接"/wiki/test_page.html“的页面中添加了一个显式href链接:
<a class="bottom_link" href="http://website.com/wiki/test_page.html">Test page</a>通过这种方式,应用了最后一次重写规则( RewriteRule ^/(.*) http://localhost:9674/++vh++http:%{SERVER_NAME}:80/++/$1 [P,L] ),80端口上的请求被转发到Zope3的9674 HTTP端口。
在下面的RewriteCond中,我让您注意到当我浏览所有HTTPS网站时,RewriteCond %{HTTPS} on是不匹配的。
# rewrite HTTPS to HTTP for test_page.html
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/wiki/test_page\.html [NC]
RewriteRule ^/(.*) http://localhost:9674/++vh++http:%{SERVER_NAME}:80/++/$1 [P,L]是因为Apache2不能检测Zope3 (8443或443)的HTTPS端口吗?
现在,我想将/wiki/test_page.html上的HTTPS请求直接转发到Zope3服务器上的HTTP请求(该请求位于9674端口上)。我认为解决办法可能来自修改这一重写规则:
RewriteRule ^/(.*) http://localhost:9674/++vh++http:%{SERVER_NAME}:80/++/$1 [P,L]例如,我试图对其进行如下修改:
RewriteRule ^/(.*) http://localhost:9674/++vh++https:%{SERVER_NAME}:443/++/$1 [P,L]`或
RewriteRule ^/(.*) http://localhost:9674/++vh++https:%{SERVER_NAME}:8443/++/$1 [P,L]不幸的是,这是行不通的:例如,如果我单击包含此链接的页面中的"page.html“链接,RewriteRule上的链接都不会被重写。
欢迎任何帮助。
发布于 2015-05-29 05:22:08
在你的vhost文件里,规则对我来说很好。确保在每次更改后重新启动apache,并清除缓存,因为301重定向会被浏览器缓存。此外,您也可以将您的规则合并为1,如下所示。那应该管用。
# www to non www and http to https
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC, OR]
RewriteCond %{REQUEST_URI} !^/wiki/test_page.html [NC]
RewriteRule ^/?(.*) https://website.com/$1 [R=301,L]https://stackoverflow.com/questions/30520594
复制相似问题