[嗨,我想知道如何强制使用https://www.example.com而不是https://example.com或www.example.com。我使用Hostinger发布网站,使用Windows,并使用Visual Studio Code。
所以我发现Hostinger(我的网络托管公司)想出了这个解决方案!因此,这里是放入您的.htaccess文件的代码(至少对于Hostinger而言)
RewriteEngine on
# Force www: from http://stackoverflow.com/a/4958847/1078583
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Force SSL: From http://stackoverflow.com/q/24322035/
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE]