强制重定向到除一个页面之外的所有页面的 SSL [英] Force redirect to SSL for all pages apart from one

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

问题描述

我正在尝试使用 apache2 的 mod_rewrite 强制 SSL 连接到网站.到目前为止,它在网站的 <VirtualHost> 条目中使用以下内容可以正常工作:

I'm trying to use apache2's mod_rewrite to force SSL connections to a website. So far, it's working fine with the following in the site's <VirtualHost> entry :

RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [QSA,NC,R,L]

这运行良好,并且重定向了所有内容,这正是我想要的.

This is working well, and redirects everything, which is what I wanted.

但是,网站上有一个特定页面使用了 Google 地图 API,该 API 无法通过 SSL 使用,因此会在浏览器中触发混合内容警告.所以,我希望这个仅限地图的页面不要重定向,并使用正常的非 ssl 连接.

However, there's one particular page on the site which uses the Google maps API, which isn't available over SSL and hence triggers mixed content warnings in the browser. So, I'd like this one, map-only page not to redirect, and use the normal, non-ssl connection.

我不希望使用 SSL 的 URL 的格式为 /thing/add/{ID}/page3,其中 {ID} 是一个数值.

The URL that I don't want SSL on has the form /thing/add/{ID}/page3 where {ID} is a numeric value.

这可能吗?

推荐答案

RewriteEngine On

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^thing/add/\d+/page3$ - [L]

RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(thing/add/\d+/page3) $ http://%{HTTP_HOST}/$1 [QSA,NC,R,L]

RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [QSA,NC,R,L]

规则从上到下处理;如果不在 SSL 上,第一个停止重写地图页面;如果通过 SSL 访问,第二个(可选)会将这些页面重定向到非安全页面;除此之外,旧规则适用.

The rules are processed top to bottom; the first one stops rewrite for maps page if not on SSL; the second one (optional) redirects these pages to non-secure if accessed via SSL; for all else, the old rule applies.

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

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