简体   繁体   English

mod_rewrite将所有重定向到https(一个文件除外)

[英]mod_rewrite redirect all to https except one file

i use this code 我用这个代码

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

to redirect all request to HTTPS and that is ok. 将所有请求重定向到HTTPS,没关系。

Now I want same thing except one file index810.php 现在我想要的只是一个文件index810.php

when i write like this 当我这样写

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

i get too many redirects, any suggestions. 我得到太多重定向,任何建议。

Thank you in advance 先感谢您

A solution is to use a non rewriting rule: 一种解决方案是使用非重写规则:

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

Your pattern was wrong: 您的模式是错误的:

  • there is a space between ^ and index810.php 在^和index810.php之间有一个空格
  • %{REQUEST_URI} is all the HTTP path (ie, if at document root, it would be =/index810.php ) %{REQUEST_URI}是所有HTTP路径(即,如果位于文档根目录, =/index810.php

The accepted answer didn't work for me. 接受的答案对我不起作用。 This did however: 但是这样做:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM