-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.

0

1 Answer 1

-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.

2
  • Could you please explain the solution. Don't quite understand it
    – Ashrith
    Mar 10, 2014 at 13:18
  • this post can help you, you just need a default virtual host, for unmatching request serverfault.com/questions/82306/…
    – c4f4t0r
    Mar 10, 2014 at 13:32

Not the answer you're looking for? Browse other questions tagged .