apache2 - https 重定向到给定页面的 http

you*_*t13 5 apache .htaccess mod-rewrite url-rewriting url-redirection

我有一个关于将几个页面的 HTTPS 重定向到 HTTP 的特定问题。

我在 Zope 前面有 Apache2。

这是我的 VirtualHost 在端口 80 上的配置:

<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>
Run Code Online (Sandbox Code Playgroud)

之后,当 Zope 侦听 SSL 8443 端口时,我应用以下 iptables 规则:

iptables -t nat -A PREROUTING -p tcp -m tcp --dport 443 -j REDIRECT --to-ports 8443
Run Code Online (Sandbox Code Playgroud)

所以我的重写规则将 80 重定向到 443,而 iptables 将 443 重定向到 8443。

在这种情况下,我如何将一个页面(比如“ https://website.com/wiki/test_page.html ”)重定向到“ http://website.com/wiki/test_page.html ”。

我尝试添加以下规则:

# if https on then turn off
RewriteCond %{HTTPS} on
RewriteRule ^/wiki/test_page.html http://%{HTTP_HOST}%{REQUEST_URI}
Run Code Online (Sandbox Code Playgroud)

但它不起作用。

而不是做另一个重写规则,我认为应该更容易防止页面“/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}
Run Code Online (Sandbox Code Playgroud)

没有成功

更新 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]
Run Code Online (Sandbox Code Playgroud)

有了这些规则,我可以使用 HTTPS 链接浏览我所有的网站,除了 /wiki/test_page.html 页面。为此,我在包含链接“ /wiki/test_page.html”的页面中放入了一个显式的 HTTP href 链接:

<a class="bottom_link" href="http://website.com/wiki/test_page.html">Test page</a>
Run Code Online (Sandbox Code Playgroud)

这样就应用了最后的重写规则(RewriteRule ^/(.*) http://localhost:9674/++vh++http:%{SERVER_NAME}:80/++/$1 [P,L]),80端口的请求被转发到Zope3的9674 HTTP端口。

在下面RewriteCond,我让你注意到,RewriteCond %{HTTPS} on当我浏览我所有的 HTTPS 网站时,不匹配。

# 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]
Run Code Online (Sandbox Code Playgroud)

是不是 Apache2 检测不到 Zope3 的 HTTPS 端口(8443 或 443)?

现在,我想直接将 HTTPS 请求转发/wiki/test_page.html到 Zope3 服务器(位于 9674 端口)上的 HTTP 请求。我认为解决方案可能来自修改这个重写规则:

RewriteRule ^/(.*)  http://localhost:9674/++vh++http:%{SERVER_NAME}:80/++/$1 [P,L]
Run Code Online (Sandbox Code Playgroud)

例如,我尝试将其修改如下:

RewriteRule ^/(.*)  http://localhost:9674/++vh++https:%{SERVER_NAME}:443/++/$1 [P,L]`
Run Code Online (Sandbox Code Playgroud)

或者

RewriteRule ^/(.*)  http://localhost:9674/++vh++https:%{SERVER_NAME}:8443/++/$1 [P,L]
Run Code Online (Sandbox Code Playgroud)

不幸的是,这不起作用:例如,如果我从包含此链接的页面中单击链接“ https://website.com/wiki/test_page.html ”,则不会为上述 RewriteRule 重写 URL。

欢迎任何帮助