How Do I Redirect Http:// And Non-www Requests to Https://www.?

Avatar
  • updated
  • Answered

When people visit my site without www or without https I would like them redirected to https://www.domain.com

I have the following code in htaccess:

RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.domain.com%{REQUEST_URI} [L,R=301,NE]


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

It works in some cases, but if I visit http://domain.com it does not redirect.

Can you help?

Avatar
anonymous
  • Answered

Hello Tim,

Thanks for posting your question regarding redirecting http:// and non-www requests to https://www. This is generally controlled by the Content Management System that you used to build your website. Depending on that software you can adjust this in their settings. Although you may be able to code your .htaccess file for redirects, it may disrupt the functionality of the CMS. How did you build your website?

I look forward to your response to assist you further.

Sincerely,

Carlos D.