除了Apache中的几页之外,如何强制重写为HTTPS? [英] How to force rewrite to HTTPS except for a few pages in Apache?
本文介绍了除了Apache中的几页之外,如何强制重写为HTTPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将 Apache 中的所有页面强制重定向到 HTTPS,除了少数页面.这种情况如何在Apache中编写重写规则?
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]
第一个规则集会将所有未通过 HTTPS 访问的页面重定向到相同的 URL 但不是 /page1/
或 /page2/
https://.第二个规则集将确保 /page1/
和 /page2/
被重定向回 http://
如果它们是通过访问https://
.
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://
.
这篇关于除了Apache中的几页之外,如何强制重写为HTTPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文