重定向到 SSL,但一个 URL 除外



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

我已经能够通过我的 .htaccess 文件将任何非 SSL 连接重定向到 https,如下所示:

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

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

URL 始终在主目录前面加上"预览"一词。

这是我尝试过的,不幸的是没有成功:

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 文件中缺少什么吗?

谢谢 -保罗

使用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

还要确保清除浏览器缓存。

最新更新