How do I block someone else's domain pointing to my Apache hosted website? How do I block someone else's domain pointing to my Apache hosted website? apache apache

How do I block someone else's domain pointing to my Apache hosted website?


I agree with @Azrael but would like to expand on it:

You can redirect their domain to a different page on a case by case basis but what I would recommend doing and what I do on most of my servers is deny all traffic except the traffic for the correct domain.

Apache 2.4 and newer:

<VirtualHost *:80>    ServerName catchall    <Location />        Require all denied    </Location></VirtualHost><VirtualHost *:80>    ServerName allowed.com    <Location />        Require all granted    </Location></VirtualHost>

Apache 2.2 and older:

<VirtualHost *:80>    ServerName catchall    <Location />        Order allow,deny        Deny from all    </Location></VirtualHost><VirtualHost *:80>    ServerName allowed.com    <Location />        AllowOverride All        Order allow,deny        allow from all    </Location></VirtualHost>

The way this works is that Apache uses the ServerName to filter requests, however any requests that do not match any VirtualHosts ServerNames are sent to the first VirtualHost on the server, in this case the ServerName in the first VirtualHost is 'Catchall' which will not match any requests as it is not a valid domain name but will instead, as it is the first VirtualHost, serve all non matching domains. We then use the location container to define the allow or deny directives.

If you want to use file system instead of url specific directives such as 'Allow overide all' you can use the directory container instead of location in the following format:

DocumentRoot /var/www/html<Directory "/var/www/html">    Require all granted    Allow overide all</Directory>


If the domain is not yours there is no way to like.. not point it to your server, however you can point it to a serperate page by using VirtualHost's

Do this by doing the following, create a folder with a desired html / php file inside saying that the page is not existing or whatever

then edit your VirtualHosts file, let's say your using apache, that file would be in the following directory:/etc/apache2/sites-available/open the file called default and add the following code:

<VirtualHost *:80>DocumentRoot /www/example2ServerName www.example.org</VirtualHost>