Sandeep Vishwakarma
Sandeep Vishwakarma

Reputation: 576

Redirection http to https and non-www to www

I am using this code for SSL migration:

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


RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

The problem that I am facing is that it is working is that the redirection is not working for most of the folders and URLs but in a few cases it is working and that is what is baffling me.

If the code was correct, it should work for every URL on the site instead of a few or it shouldn't work at all. When I remove the first re-write condition in the .htaccess, the site works just fine.

This is the error that I am getting:

https/www.mysite.com:443/some-folder/xyz.html

Can anybody help? Thanks in advance.

Upvotes: 2

Views: 58

Answers (1)

user1844933
user1844933

Reputation: 3417

try this...

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

Upvotes: 1

Related Questions