There is a webserver which has example.com, www.example.com, my.example.com, shop.example.com, static.example.com. All sites except www.example.com is on https. My problem is when I type randomstring.example.com -> shop.example.com gets served. But I want nothing to be served. For example mail.google.com is a valid subdomain. if you type johndoe.google.com you see "This webpage is not available". How to achieve this via Vhost/.htaccess file.
1 Answer
You can use this in your .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)?example\.com [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com [NC]
RewriteRule .* http://www.example.com/blog/%1 [R=301,L]
I hope I helped you.
-
-
this post can help you, you just need a default virtual host, for unmatching request serverfault.com/questions/82306/…– c4f4t0rMar 10, 2014 at 13:32