[英]Redirect www to https://www in .htaccess
So far I have .htaccess file which is able to redirect correctly from ( domain.com
) to ( https://www.domain.com
) but not working if I go to www.domain.com
and it must redirect ( www.domain.com
) to ( https://www.domain.com
) 到目前为止,我有.htaccess文件能够正确地从(
domain.com
)重定向到( https://www.domain.com
),但如果我去www.domain.com
并且它必须重定向( www.domain.com
)到( https://www.domain.com
)
I need ( https://www
) always before my site url 我总是需要(
https://www
)在我的网站网址之前
my .htaccess file 我的.htaccess文件
RewriteEngine On
RewriteCond !{HTTPS} off
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Replace your first 2 redirect rules with this rule: 使用此规则替换您的前2个重定向规则:
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301,NE]
Make sure to clear your browser cache before testing this. 在测试之前,请务必清除浏览器缓存。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.