繁体   English   中英

Mod重写,将所有URL重定向到https(特定的URI除外),然后将该URI从https重定向到http

[英]Mod rewrite, redirect all to https except specific URI and redirect that URI from https to http

因此,我碰到了一堵墙,尝试了许多不同的选项和配置。 我正在尝试将我的网站重定向到https,但我想将一个特定的URI从https重定向到http,然后保持http。 我将不胜感激任何帮助。 这是通过virtualhost配置完成的。 以下是我与ssl.conf和mysite.conf配对使用的设置。 但是,我一直收到重定向循环或无法加载的页面。

mysite.conf

RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !/example
RewriteRule ^(.*)$ https://my.site.com$1 [R,L]

要么

RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} ^(/|page1|page2)
RewriteRule ^(.*)$ https://my.site.com$1 [R,L]

要么

RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !=/example
RewriteRule ^(.*)$ https://my.site.com$1 [R,L]

要么

RewriteCond %{REQUEST_URI} =/example
RewriteRule ^(.*)$ http://my.site.com$1 [R,L]

再加上以上之一。

然后在ssl.conf中

RewriteEngine on
RewriteCond %{REQUEST_URI} =/example
RewriteRule ^(.*)$ http://my.site.com$1 [R,L]

这应该为您做。 首先放置最具体的规则(对于/example )。

RewriteEngine on

RewriteCond %{HTTPS} =on
RewriteRule ^/?example$ http://my.site.com/example [R=301,L]

RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_URI} !^/?example$
RewriteRule ^/?(.*)$ https://my.site.com/$1 [R=301,L]

这应该可以在服务器(.conf)或目录(.htaccess)上下文中使用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM