除了一个文件以外,mod_rewrite都将redirect到https

我使用这个代码

RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

将所有请求redirect到HTTPS,这是没问题的。

现在我想要除了一个文件index810.php以外的其他东西

当我这样写

 RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} !^ index810.php RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} 

我得到太多的redirect,任何build议。

先谢谢你

解决方案是使用非重写规则:

 # do nothing for /index810.php RewriteRule ^index810\.php$ - [L] # else ... RewriteCond %{HTTPS} off RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} 

你的模式是错误的:

  • ^和index810.php之间有一个空格
  • %{REQUEST_URI}是所有的HTTP路径(即,如果在文档根目录下,它将是=/index810.php

接受的答案不适合我。 但是,

 RewriteCond %{THE_REQUEST} !/index810\.php [NC] RewriteCond %{HTTPS} off RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI}