linux - mod_rewrite REQUEST_URI 混淆

标签 linux apache mod-rewrite ssl

我想在整个站点上强制使用 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/

强制 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$1 [R=301,L]

但是 /cards/locations_and_contacts 和任何页面都没有被排除在 ssl 访问服务之外。有人可以告诉我我的规则集有什么问题吗?

最佳答案

:)

...

您忘记了“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$1 [QSA,R=301,L]

两个提示:


请尝试使用RewriteLog 指令:它可以帮助您追踪此类问题:

# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On

我最喜欢的正则表达式检查工具:

http://www.quanetic.com/Regex (不要忘记选择 ereg(POSIX) 而不是 preg(PCRE)!)

关于linux - mod_rewrite REQUEST_URI 混淆,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8511431/

相关文章:

apache - 试图通过 htaccess 强制使用 https,但发生了奇怪的行为。它删除了一个正斜杠

apache - 在 htaccess 文件中使用 RewriteMap

regex - 在 htaccess 中用连字符替换 %20

php - .htaccess 影响我的 php 包括

linux - 编写一个列出所有文件和子目录的 bash 脚本

linux - 没有ssh的没有密码文件的rsync

linux - 如何使用 TUI 制作 Linux 程序

未在 Aws Ec2 实例上为 PHP 7.2 执行 PHP 代码

java - mod_rewrite、RewriteMap、RewriteLock 和线程

python - 下载后文件的可执行权限发生变化。是否有任何协议(protocol)或方法可以完好无损许可?