如何更改.htaccess文件重定向到www,而不是http? [英] How to change .htaccess file to redirect to www, not http?
本文介绍了如何更改.htaccess文件重定向到www,而不是http?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是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).
这篇关于如何更改.htaccess文件重定向到www,而不是http?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文