Forum Topic: Redirecting from http to https

Forum: .htaccess Forum : Redirecting • Posted by Chris Owen • Updated:

So I’m redirecting all my traffic from http to https, but there is only page I don’t want to redirect to https…

So here is my htaccess rule..

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Now I have a page named api.php that i don’t want to redirect to https.

I’m unable to solve this, I only get redirection errors, a solution to this problem would be welcomed.

Thanks

2 Replies to “Redirecting from http to https”

Posted by Jeff Starr

Hi Chris,

Have you tried something like this:

RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} !/api\.php [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI}

That basically excludes the api.php page from the rewrite rule.

Posted by Chris Owen •

This is exactly what I was waiting for…

It worked flawlessly.. here’s an alternative that also worked for those who might need it..

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule !^api\.php https://%{HTTP_HOST}%{REQUEST_URI} [NC,L,R=301,NE]
RewriteCond %{HTTPS} on
RewriteRule ^api\.php http://%{HTTP_HOST}%{REQUEST_URI} [NC,L,R=301,NE]

Yeah but yours is much simple, so I’m going with yours… Thanks for the help…