htaccess redirect all subdomains + www to domain with cname, vhosts and htaccess
.htaccess, apache, mod-rewrite, php, regex
Solution
redirect *.domain.com -> domain.com
Just change your rule to this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.(domain\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L,NE]
Problem
I have a rather simple problem for someone who knows, I just cant find the answer that I need. I have moved to vps and try to configure vm by myself. I need redirects: - domain.com - default - www.domain.com -> domain.com - *.domain.com -> domain.com I`ve already done .htaccess for www -> non-www, so I have: ``` RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] ``` Added A and CNAME: - www - @ - * - @ Added virtualhost - ServerAlias www.domain.com *.domain.com Am I doing right (CNAME, vhost, .htaccess) or it can me done simplier? Can you please help me redirect *.domain.com -> domain.com (guess in .htaccess) ?