mod_rewrite redirect all to https except one file

瘦欲@ 提交于 2020-01-05 04:29:08

问题


i use this code

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

to redirect all request to HTTPS and that is ok.

Now I want same thing except one file 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


回答1:


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
  • %{REQUEST_URI} is all the HTTP path (ie, if at document root, it would be =/index810.php)



回答2:


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}


来源:https://stackoverflow.com/questions/19141216/mod-rewrite-redirect-all-to-https-except-one-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!