如何强制重写到HTTPS除了在Apache的几页? [英] How to force rewrite to HTTPS except for a few pages in Apache?
本文介绍了如何强制重写到HTTPS除了在Apache的几页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要强制重定向所有Apache以HTTPS网页,除了几页。如何写重写规则在Apache中这个条件?
解决方案
RewriteEngine叙述在的RewriteCond%{HTTPS} =关闭
的RewriteCond%{REQUEST_URI}!^ \\ /第1页\\ /
的RewriteCond%{REQUEST_URI}!^ \\ / 2页\\ /
重写规则的https(*)://%{HTTP_HOST} / $ 1 [L,R = 301]的RewriteCond%{} HTTPS上=
的RewriteCond%{REQUEST_URI} \\ /第1页\\ / [OR]
的RewriteCond%{REQUEST_URI} \\ / 2页\\ /
(。*)重写规则的http://%{HTTP_HOST} / $ 1 [L,R = 301]
第一条规则集将重定向所有网页无法通过HTTPS访问,而不是 /第1页/
或 /第2页/
到相同的URL,但的https://
。第二条规则集将确保 /第1页/
和 /第2页/
被重定向到 HTTP://
如果他们是通过 HTTPS访问://
I need to force redirect all the pages in Apache to HTTPS except for a few pages. How to write rewrite rule in Apache for this condition?
解决方案
RewriteEngine On
RewriteCond %{HTTPS} =off
RewriteCond %{REQUEST_URI} !^\/page1\/
RewriteCond %{REQUEST_URI} !^\/page2\/
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} \/page1\/ [OR]
RewriteCond %{REQUEST_URI} \/page2\/
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]
The first rule-set will redirect all pages not accessed via HTTPS, and that are not /page1/
or /page2/
to the same URL but https://
. The second rule-set will make sure that /page1/
and /page2/
are redirected back to http://
if they are accessed via https://
.
这篇关于如何强制重写到HTTPS除了在Apache的几页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文