下面是code。在我的.htaccess文件。如何更改它重定向访问者的https:// WWW
,而不是的http://
选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则。的index.php [L]
解决方案
紧随 RewriteEngine叙述在
指令后,将以下内容:
的RewriteCond%{} HTTPS关闭[OR]
的RewriteCond%{HTTP_HOST}!WWW 。
重写规则* HTTPS://www.example.com% {REQUEST_URI} [R = 301,L]
这将同时处理 HTTP
到 HTTPS
和非www
到 WWW
重定向。需要注意的是外部重定向通常应该来的在的内部重写(这是您当前拥有)。
Below is the code in my .htaccess file. How do I change it to redirect visitors to https://www
and not http://
.
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
解决方案
Immediately after the RewriteEngine On
directive, place the following:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !www.
RewriteRule .* https://www.example.com%{REQUEST_URI} [R=301,L]
This will handle both the http
to https
and non-www
to www
redirection. Note that external redirections should generally come before internal rewrites (which is what you currently have).