htaccess将http://subdomain.example.com重定向到www.subdomain.example.com

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了htaccess将http://subdomain.example.com重定向到www.subdomain.example.com相关的知识,希望对你有一定的参考价值。

我可以使用下面的代码将我的网站http://example.com重定向到www.example.com。

RewriteCond %{HTTP_HOST} ^example.com <br />
RewriteRule (.*) http://www.example.com/$1 [R=301,L] 

但是没有获得http://subdomain.example.com的解决方案到www.subdomain.example.com?

答案

试试吧:

RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]

以上是关于htaccess将http://subdomain.example.com重定向到www.subdomain.example.com的主要内容,如果未能解决你的问题,请参考以下文章

.htaccess 重定向到子文件夹并隐藏在 uri

.htaccess 重定向太多次

无法访问 subdomain.localhost/error/ 中的“错误”文件夹

Apache 2.4:IF 规则的优先级?

在本地测试 Facebook 评论插件

自定义设计 Cookie