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

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

问题描述

我想使用的Apache2的mod_rewrite强制到一个网站的SSL连接。到目前为止,它的正常工作,在该网站的&LT以下;虚拟主机> 条目:

  RewriteEngine叙述在
的RewriteCond%{SERVER_PORT}!^ $ 443
(。*)重写规则^ $ https://开头%{HTTP_HOST} / $ 1 [QSA,NC,R,L]

这是运作良好,并重定向一切,这就是我想要的东西。

然而,有它使用谷歌地图API,这是不是可以使用SSL,从而触发在浏览器中混合内容的警告网站上的一个特定的页面。所以,我想这其中,地图只页面不重定向,并且使用正常,非SSL连接。

这是我不希望的SSL URL的形式 /事/添加/ {ID} / 3页,其中 {ID} 是一个数值。

这可能吗?


解决方案

  RewriteEngine叙述在的RewriteCond%{SERVER_PORT}!^ $ 443
重写规则^事情/添加/ \\ D + /第3页$ - [L]的RewriteCond%{SERVER_PORT} ^ $ 443
重写规则^(事/添加/ \\ D + / 3页)$的http://%{HTTP_HOST} / $ 1 [QSA,NC,R,L]的RewriteCond%{SERVER_PORT}!^ $ 443
(。*)重写规则^ $ https://开头%{HTTP_HOST} / $ 1 [QSA,NC,R,L]

的规则进行处理从上到下;第一个停止重写的地图页面,如果不是SSL;如果通过SSL访问的第二个(可选)重定向这些页面非安全;对于一切,老规则适用。

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.

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.

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

Is this possible?

解决方案

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]

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天全站免登陆