.htaccess 重定向 - 自动添加 www.如果不存在子域 [英] .htaccess redirect - automatically add www. if no subdomain exists

查看:21
本文介绍了.htaccess 重定向 - 自动添加 www.如果不存在子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要任何 www.仅当子域不存在时才自动添加到我的域中.我确实希望子域绕过此重定向.

I need any www. added automatically to my domain ONLY IF a subdomain is not already there. I do want subdomains to bypass this redirect.

我该怎么做?

推荐答案

要在没有子域时自动将 www 添加到您的域名,请将其添加到您文档中的 htaccess 文件中根:

To automatically add a www to your domain name when there isn't a subdomain, add this to the htaccess file in your document root:

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

这篇关于.htaccess 重定向 - 自动添加 www.如果不存在子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆