I build a website using NodeJs and defined the homepage in package.json to be "https://www.example.com". After npm run build I uploaded files to public folder and created htaccess file with the following code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
Once I type http or https://example.com I am being redirected to https://www.example.com, but the site can`t be reached. How do I make it reachable by keeping the redirections from http and non-www URLs working?
I have tried deleting RewriteConds and RewriteRules responsible for redirections in .htaccess, thus making it possible to access the website using https://exapmple.com, but this is not the result I am looking for. I was also trying many different .htaccess code variations like
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
But this brought me to the same results. It seems like I am missing something.