Rahul
Rahul

Reputation: 321

htaccess Canonicalization for https url (http://www)

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]
RewriteCond %{HTTPS} off 

RewriteCond %{HTTPS_HOST} !^www.website.com$ [NC]
RewriteRule ^(.*)$ https://www.website.com/$1 [L,R=301]

I used this to redirect:

I tried this code changing http to https, but still it does not work. Is there anything that I'm doing wrong?

Upvotes: 0

Views: 224

Answers (2)

Rahul
Rahul

Reputation: 321

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]

This code worked for me. Thank you!

Upvotes: 0

Croises
Croises

Reputation: 18671

You can use:

RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} libwww-perl.* 
RewriteRule .* ? [F,L]

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTPS_HOST} !^www.website.com$ [NC]
RewriteRule ^(.*)$ https://www.website.com/$1 [L,R=301]

With [OR]

Upvotes: 1

Related Questions