重定向到SSL(一个URL除外) [英] redirect to SSL with the exception of one URL

查看:193
本文介绍了重定向到SSL(一个URL除外)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I run a small bootstrap themes site that allows users to upload themes and templates.

我已经可以通过以下命令通过.htaccess文件将任何非SSL连接重定向到https:

I've been able to redirect any non SSL connection to https via my .htaccess file with the following:

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

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

I now need to redirect the user to non-SSL for one page in particular. It's a page containing an iframe that loads a preview from the theme authors site and these sites aren't always served via SSL.

URL始终带有单词 preview

The URL always has the word 'preview' preceded by the domin.

这是我尝试过的,很遗憾没有成功:

Here's is what I've tried, unfortunately without success:

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

Any idea why it's not working or what I'm missing from the .htaccess file?

谢谢,
-Paul

Thanks, -Paul

推荐答案

使用 THE_REQUEST 代替 REQUEST_URI 可能会由于其他模块或规则而更改:

Use THE_REQUEST instead of REQUEST_URI which might change due to other modules or rules:

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

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

Also make sure to clear your browser cache.

这篇关于重定向到SSL(一个URL除外)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆