1

I setup a wildcard A record on my domain registrar. Now if a user access a missing subdomain on my domain, they will be redirected to the homepage. Currently my initial setup was this:

<VirtualHost *:80>
  ServerAdmin webmaster@localhost
  RewriteEngine On
  RewriteRule ^(.*)$ http://domain.com$1 [R]
  DocumentRoot /var/www
  <Directory />
    Options FollowSymLinks
    AllowOverride None
  </Directory>
  # more below...
</VirtualHost>

Any wildcard subdomain or if my IP is entered via URL will redirect to the homepage. Can I do something about this that will redirect (HTTP redirect perhaps) the wildcard subdomains to 404 page instead of to homepage?

Leandro Garcia
  • 3,138
  • 11
  • 32
  • 44
  • May be you could use a PHP script to check hostname and generate a 404 error if necessary. – Salman A Sep 09 '12 at 16:29
  • Probably, but what I have in mind is like a "could not find host" page. Like in any other sites. (eg. deads.google.com) – Leandro Garcia Sep 09 '12 at 16:32
  • @SalmanA - why'd you deleted your answer? It's working and probably what I was looking for. – Leandro Garcia Sep 09 '12 at 16:44
  • deads.google.com does not seem to work (nslookup fails). I would really like to see an example of how others are doing this. – Salman A Sep 09 '12 at 16:47
  • @SalmanA - exactly, that was my point. I want to end up like that. Say in my Google Chrome, if I visit deads.google.com it returns "Oops! Google Chrome could not find deads.google.com" – Leandro Garcia Sep 09 '12 at 16:48
  • OMG, that pages is built into the browser, does not come from a server :) But still, having a custom made dead-domain page is a good idea, you can tell search engines/humans that the page does not exist anymore, or it has moved permanently to a new location. – Salman A Sep 09 '12 at 16:57

1 Answers1

2

Try changing your rewrite rule to this; it should fire the Apache 404 error page:

RewriteRule .* - [R=404,L]

The error page can be set to a custom HTML or PHP page using the ErrorDocument directive. While HTML pages work nicely, a PHP script allows you to do a little more.

You can probably create a nice looking page on the wildcard domain, and do this instead: RewriteRule .* /domain-doesnt-exist.php [L] The page I mentioned above could send a 404 header in case you want search engines to ignore the page.

Salman A
  • 262,204
  • 82
  • 430
  • 521