Linux mod_rewrite REQUEST_URI 混淆
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8511431/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mod_rewrite REQUEST_URI confusion
提问by Alpha01
I want to force ssl
access on an entire site, except for the following pages:
我想强制ssl
访问整个网站,但以下页面除外:
www.example.com/loans_and_lines/home_loans.html www.example.com/cards
www.example.com/cards/international-ministries.html
www.example.com/cards/international-ministries/donation-3.html
www.example.com/locations_and_contacts/
www.example.com/loans_and_lines/home_loans.html www.example.com/cards
www.example.com/cards/international-ministries.html
www.example.com/cards/international-ministries/donation-3.html
www.example.com/locations_and_contacts/
Force ssl
:
力ssl
:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/personal/loans_and_lines/home_loans\.html
RewriteCond %{REQUEST_URI} !^/cards/$
RewriteCond %{REQUEST_URI} !^/cards/international\-ministries\.html
RewriteCond %{REQUEST_URI} !^/cards/international\-ministries/donation\-3\.html
RewriteCond %{REQUEST_URI} !^/locations_and_contacts/$
RewriteRule (.*) https://www.example.com [R=301,L]
However neither of the /cards
or /locations_and_contacts
and any of the pages are being excluded from being served with ssl
access. Can someone tell me what's wrong with my set of rules?
然而,/cards
或/locations_and_contacts
和任何页面都不会被排除在ssl
访问权限之外。有人能告诉我我的一套规则有什么问题吗?
采纳答案by Olivier Pons
:)
:)
...
...
You forgot the "OR" directive. Here's what should work (and maybe you've forgotten the QSA directive in the redirect as well (maybe not)):
您忘记了“OR”指令。这是应该起作用的(也许您也忘记了重定向中的 QSA 指令(也许不是)):
# Force SSL
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/personal/loans_and_lines/home_loans\.html [OR]
RewriteCond %{REQUEST_URI} !^/cards/$ [OR]
RewriteCond %{REQUEST_URI} !^/cards/international\-ministries\.html [OR]
RewriteCond %{REQUEST_URI} !^/cards/international\-ministries/donation\-3\.html [OR]
RewriteCond %{REQUEST_URI} !^/locations_and_contacts/$
RewriteRule (.*) https://www.example.com [QSA,R=301,L]
Two hints:
两个提示:
Please try to use the RewriteLog
directive: it helps you to track down such problems:
请尝试使用该RewriteLog
指令:它可以帮助您追踪此类问题:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
My favorite tool to check for regexp:
我最喜欢的检查正则表达式的工具:
http://www.quanetic.com/Regex(don't forget to choose ereg(POSIX) instead of preg(PCRE)!)
http://www.quanetic.com/Regex(不要忘记选择 ereg(POSIX) 而不是 preg(PCRE)!)