使用 .htaccess 在 Angular 5 应用程序的 URL 中强制使用 SSL 和 www



我有一个基于 Angular 5 的网站,我需要在这个网站中使用 www 实现强制 SSL。所以基本上我需要域的任何变体,如 http://example.com 或 example.com 或 www.example.com 等。全部重定向到 https://www.example.com

目前使用的.htaccess文件如下:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]

我尝试了来自多个资源的解决方案,其中一个例子是使用 htaccess 强制 SSL 和 WWW,通过在上述代码的底部添加提到的代码,但没有运气。

任何帮助都非常感谢。

你试过这个吗:

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

你也可以使用它

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

最新更新