mod_rewrite将所有内容重定向到https,但一个文件除外

Vla*_*vic 1 apache mod-rewrite

我用这个代码

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
Run Code Online (Sandbox Code Playgroud)

将所有请求重定向到HTTPS,这没关系.

现在我想要同样的东西,除了一个文件index810.php

我这样写的时候

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

我得到太多的重定向,任何建议.

先感谢您

jul*_*ulp 5

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

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

你的模式错了:

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