在相同URL中强制使用SSL和www

问题描述 投票:0回答:1

[嗨,我想知道如何强制使用https://www.example.com而不是https://example.com或www.example.com。我使用Hostinger发布网站,使用Windows,并使用Visual Studio Code。

web-config
1个回答
0
投票

所以我发现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]
© www.soinside.com 2019 - 2024. All rights reserved.