如何添加子域名在.htaccess和URL强制WWW [英] How to add subdomain in .htaccess and force WWW in url

查看:109
本文介绍了如何添加子域名在.htaccess和URL强制WWW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code强制WWW的网址

I have the following code to force WWW in url

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

我想添加一个子域max.example并参考www.example.com/update/max~~V目录 如果我不添加任何规则,max.example.com会重定向到www.example.com/update/max~~V。如果我删除力WWW的URL它的工作原理。但我仍然需要在URL强制WWW。如何编写规则?

I want to add a subdomain max.example and refer to www.example.com/update/max directory If I do not add any rule, max.example.com will redirect to www.example.com/update/max . If I remove force WWW in url it works. But I still need force WWW in url. How to write the rule?

谢谢!

推荐答案

更​​改您的规则如下:

Change your rule to this:

RewriteCond %{HTTP_HOST} !^(www|max)\.example\.com$ [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L]

这篇关于如何添加子域名在.htaccess和URL强制WWW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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