通过.htaccess打开HTTPS

我目前有一个网站,我使用.htaccess为网站的某些部分打开https:

RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} (evaluate/purchase*) RewriteRule (.*) https://mydomain.com%{REQUEST_URI} 

“评估”文件夹中有多个以“购买”开头的文件,所有这些文件都需要保护。 到目前为止,这工作。

我现在需要保护其他几个文件和目录,但是将它们添加为重写条件似乎不起作用:

 RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} (evaluate/purchase*) RewriteCond %{REQUEST_URI} (another_dir/file.php) RewriteCond %{REQUEST_URI} (please_secure_me.php) RewriteRule (.*) https://mydomain.com%{REQUEST_URI} 

这不是踢任何500或任何东西,它只会保护在第一个条件的文件。 我究竟做错了什么?

IIRC,RewriteCond是AND条件。

“如果所有条件都匹配,则replaceURL的replacestring继续处理。”

你现在说的是(HTTPSclosures和URI是这个和URI是这个和URI是这个)这是不正确的,因为这个URI不能同时是三个不同的东西!

你想要一个组合的AND / OR条件(closuresHTTPS AND(URI是这个OR URI是这个OR URI是这个))

尝试重复您的规则:

 RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} (evaluate/purchase*) RewriteRule (.*) https://mydomain.com%{REQUEST_URI} RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} (another_dir/file.php) RewriteRule (.*) https://mydomain.com%{REQUEST_URI} RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} (please_secure_me.php) RewriteRule (.*) https://mydomain.com%{REQUEST_URI} 

其实只要看一下2.2的文档,你可以这样做:

 RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} (evaluate/purchase*) [OR] RewriteCond %{REQUEST_URI} (another_dir/file.php) [OR] RewriteCond %{REQUEST_URI} (please_secure_me.php) RewriteRule (.*) https://mydomain.com%{REQUEST_URI} 

如果可行,这是一个更优雅的解决scheme。