[英]Redirect non WWW to WWW using htaccess without failing subdomains
I need to redirect non WWW to WWW without failing sub domains. 我需要将非WWW重定向到WWW,而不会使子域失败。 Please help me to do this.
请帮我做到这一点。
mydomain.com > www.mydomain.com
m.mydomain.com > m.mydomain.com
mydomain.com/page.php > www.mydomain.com/page.php
I am using URL rewrite. 我正在使用URL重写。 they should also remain working.
他们还应该继续工作。 This is the current htaccess file.
这是当前的htaccess文件。
Options All -Indexes
RewriteEngine On # Turn on the rewriting engine
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([a-z.]+)$ [NC]
RewriteRule ^/(.*)$ http://www.%1/$1 [R=301,L]
RewriteRule ^vid vid.php [NC,L]
AddType application/octet-stream mp3
RewriteCond %{HTTPS} =on
Thank you. 谢谢。
This rule should work for non-www to www for main domain only: 此规则仅适用于非www到www的主域:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.