我的力量www htaccess代码是:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
但我对子域名 ex:
有疑问abcdef.example.com ====> www.abcdef.example.com
我想编辑像这样的代码:
example.com ===> www.example.com
abcdefg.example.com ===> abcdefg.example.com
example.co.uk ===> www.example.co.uk
abcd.example.co.uk ===> abcd.example.co.uk
答案 0 :(得分:5)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.(co\.uk|com)
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
或更通用:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[0-9a-zA-Z-]+\.[a-zA-Z]{2,}$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]