Reputation:
I'm trying to solve my issue with .htaccess file. I found out that accessing my page with http://www.example.com redirects to https://www.www.example.com.
I have tried numerous .htaccess rules and can't figure it out. I want to redirect http to https and non www to www.
My .htaccess file:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule (.*) https://www.%1/$1 [R=301,L]
I tried separate rules or reversing order (first to https then add www) but I'm still getting double www.
Upvotes: 1
Views: 1293
Reputation: 535
Edited to work the way you asked.
Try this as your configuration in .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^(.*)$ https://www.%1%{REQUEST_URI} [R=301,L]
Upvotes: -1
Reputation:
It looks like it's a browser problem. I used Justin's rule and it works good in Safari but on Chrome it's getting double www.www still. Anyways it isn't related to .htaccess as I though first and was scratching my head why it's not working.
Upvotes: 2