Jaime
Jaime

Reputation: 328

Htaccess redirection exception

I have this rules in my htaccess in order to force https navigation:

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

But I want to add an exception for a page let's name it 'page.php'

How can I do this? Thanks!

Upvotes: 0

Views: 34

Answers (1)

anubhava
anubhava

Reputation: 785108

Just add a negative condition:

RewriteCond %{REQUEST_URI} !/page\.php$ [NC]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{REQUEST_URI} !/page\.php$ will exclude /page.php from this rule.

There is another way of doing so using negative condition in RewriteRule itself:

RewriteCond %{HTTPS} off
RewriteRule !^page\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NC,NE]

Upvotes: 2

Related Questions