I am trying to redirect my website to https://www using htaccess 301 permanent redirection rules.
I am using the below code in my htaccess file in Angular 6 build version.
Path: /mysite/dist/myfolder/.htaccess
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.yourwebsite.com/$1 [R=301,L]
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
The above code works when I open https://example.com then it redirects to https://www.example.com. This is fine.
But when I try to open example.com or http://example.com then it does not redirect to https://www.example.com.