Http to https error

Hi Am using htaccess to move my traffic from http to https as i keep getting alot of errors with it coming up with same content but when i type in the code I have seen I get an error to many redirects? :confused: any ideas?

This is the code

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

Do you have other directives in your .htaccess file?

I would change the PERMANENT 301 to TEMPORARY 302 redirection until the URL is working the way you want it to because it is remarkably difficult to change the PERMANENT 301 once it is set.

1 Like

This should do it for you. (This also redirects www. to non www)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.([^.]+.[^.]+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]

If that doesn’t work try this.

RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www. [NC]
RewriteCond %{HTTP_HOST} ^(?:www.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]

thanks this worked :slight_smile:

Does it also redirect non-www http traffic to https?

Hint: it doesn’t

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.