-1

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.

Ashrith
  • 101
  • 1

1 Answers1

-1

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.

PoLIVoX
  • 185
  • 1
  • 1
  • 6
  • Could you please explain the solution. Don't quite understand it – Ashrith Mar 10 '14 at 13:18
  • this post can help you, you just need a default virtual host, for unmatching request http://serverfault.com/questions/82306/apache-default-catch-all-virtual-host – c4f4t0r Mar 10 '14 at 13:32