Forum Moderators: phranque
Something I noticed recently is that if I point DNS for a random domain to the IP address that has multiple <VirtualHost> entries for it, the first (or "default") <VirtualHost> will be used and the website for it displayed, but in the address bar the random domain name is displayed.
I can just imagine someone pointing an explicit domain name to my website and having the website displayed under that domain name. I use relative links, so someone could navigate the website from any domain name.
Is there any easy way to block this from happening?
If not (which I would imagine is likely the case) is there a simple way to include a mod_rewrite to redirect the domain so while a random domain name could still point to the website, the website wouldn't be displayed under it?
I've tried to do this, but haven't been successful because it redirects the other websites hosted, not just if there isn't any match.
Thanks.
You can even customize the 404 page so it says "host not found" for example.
How exactly do you do this? Specifically how do create the list and use it in a rewrite condition?
"The first virtualhost after each NameVirtualHost entry is the catchall entry, so if you don't want to return a site for non-existant domain names, create an empty site (so it returns a 404 for all page requests) as the first virtualhost after each NameVirtualHost entry.
You can even customize the 404 page so it says "host not found" for example."
By empty, do you mean like this?
<VirtualHost *:80>
ServerAdmin
DocumentRoot
ServerName
ServerAlias
RewriteEngine on
RewriteRule ^/$ /location/of/404/file.html [R=404,L]
</VirtualHost>
Or this?
<VirtualHost *:80>
RewriteEngine on
RewriteRule ^/$ /location/of/404/file.html [R=404,L]
</VirtualHost>
Thanks!