Vladimir Markovic
Vladimir Markovic

Reputation: 95

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.

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

Upvotes: 1

Views: 2590

Answers (2)

DustWolf
DustWolf

Reputation: 586

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}

Upvotes: 0

julp
julp

Reputation: 4010

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)

Upvotes: 5

Related Questions