重定向到SSL使用同一个URL除外(redirect to SSL with the excepti

2019-09-29 20:57发布

我运行一个小的引导主题的网站,允许用户上传的主题和模板。

我已经能够通过我用下面的.htaccess文件重定向到任何非SSL连接到https:

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

我现在需要将用户重定向到非SSL特别是对于一个页面。 它包含从主题作者的网站加载预览和这些网站并不总是通过SSL提供的iframe页面。

该URL总是由DOMIN前面所说的“预览”。

这里就是我试过,可惜没有成功:

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/preview [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} on

RewriteCond %{REQUEST_URI} ^/preview [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [NC,L,R]

这里有两个例子:

非预览链接 : http://www.bootstrapcovers.com/bootstrap-themes/all/free/sort.downloads/page.1

预览链接 http://www.bootstrapcovers.com/preview/1/adminlte-admin-control-panel

任何想法,为什么它不工作或者是什么我是从.htaccess文件丢失?

谢谢, - 保罗

Answer 1:

使用THE_REQUEST代替REQUEST_URI这可能会因其它模块或规则:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !\s/+preview [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} \s/+preview [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

# other rules go here

同时一定要清除浏览器缓存。



文章来源: redirect to SSL with the exception of one URL