Force https and www

Avatar
  • updated
  • Answered
VPS 1000s
I have tried to force mydomain.com to www.mydomain.com by accessing my .htaccess file and inputting

#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301,NC]

I have also tried to force HTTPS by accessing my .htaccess file and inputting

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R,L]

When that didn’t work I tried

#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [L,R=301,NC]

None of these has worked correctly. Support chat has helped as far as they can and told me to contact Managed Hosting. Managed Hosting helped me as far as they could and said to contact a Developer. Developer wants $600 to start.

If I go directly to https://www.mydomain.com it works and pages have the green lock. I type in www.mydomain.com or mydomain.com it does not redirect to https: it still goes to http:. We use Nginx as a proxy, support chat suggested that could be an issue.

Any help would be great.
Avatar
anonymous
  • Answered

Hello,

Thanks for submitting a question on how to Force https and www.

In order to perform these redirects you would need to put them in the nginx.conf as that will take priority over your Apaches .htaccess file. I found a neat little tool that seems to convert .htaccess redirects to valid NGINX syntax. If you need further help on this issue please do not hesitate to contact us back.

Best Regards,

TJ Edens