.htaccess强制子域上的www.redirect

.htaccess强制子域上的www.redirect,.htaccess,subdomain,.htaccess,Subdomain,我需要在子域上强制www。例如,sub.website.com到www.sub.website.com 我试过很多代码,例如 RewriteCond %{HTTP_HOST} !^www\.dev.website\.com RewriteRule (.*) http://www.dev.website.com/$1 [R=301,L], no success 尝试: RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} !^www\..+$ [N

我需要在子域上强制www。例如,sub.website.com到www.sub.website.com

我试过很多代码,例如

RewriteCond %{HTTP_HOST} !^www\.dev.website\.com
RewriteRule (.*) http://www.dev.website.com/$1 [R=301,L], no success
尝试:

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] no luck.
如果你有答案,请回复。谢谢
谢谢。

您可以在
文档\u ROOT/.htaccess
文件中尝试此代码:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^sub\.website.\com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

您可以在
文档\u ROOT/.htaccess
文件中尝试此代码:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^sub\.website.\com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]