Reputation: 3228
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?
Upvotes: 1
Views: 2067
Reputation: 272446
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.
Upvotes: 2