我使用NodeJS构建了一个网站,并将Package.json中的主页定义为"https://www.example.com".在NPM运行Build之后,我将文件上传到公共文件夹,并使用以下代码创建了htaccess文件:
<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>
一旦我输入http或https://example.com,我就会被重定向至https://www.example.com,但无法访问该站点.如何通过保持来自http和非www URL的重定向工作来使其可达?
我try 删除了.htaccess中负责重定向的ReWriteConds和ReWriteRules,从而可以使用https://exapmple.com访问网站,但这不是我想要的结果.我还try 了许多不同的.htaccess代码变体,比如
RewriteCond %{HTTP_HOST} ^yourdomain.com [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [L,R=301]
但这给我带来了同样的结果.我好像错过了什么.