我有一个完全通过 SSL 提供服务的网站。但我需要通过 http 在单个页面上允许外部连接。
目前在我的 http.conf 中我有
<VirtualHost *:80>
..
Redirect permanent / https://www.mysite.com/
..
</VirtualHost>
我想在这里为某个我只想服务的页面添加例外,绝不通过重定向如果可能的话作为 http...
http://www.mysite.com/directory/page.php
我尝试添加以下内容,但当然这本身可以正常工作,但与上面内容结合会创建重定向循环。
<VirtualHost *:443>
..
RewriteEngine on
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^/directory/page$ http://www.mysite.com/directory/page.php [R=301,L]
..
</VirtualHost>
答案1
尝试这个:
RewriteEngine on
RewriteCond %{HTTPS} on
RewriteRule ^/directory/page$ http://www.mysite.com/directory/page.php [R=301,L]
RewriteCond %{HTTPS} on
RewriteRule ^/directory/page.php http://www.mysite.com/directory/page.php [R,L]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/directory/page.php
RewriteRule ^/(.*) https://www.mysite.com/$1 [R,L]
答案2
以下是最终奏效的方法:
# Force HTTPS for entire site
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} !^[A-Z]+\s/directory/page.*$
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R=301,L]
# Force HTTP for a given page
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} ^/directory/page.*$
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]