How can I stop access using a domain name using htaccess?

Posted on 2010-01-02
Last Modified: 2012-05-08
I have multiple domain names pointing to a single directory. There is another domain that is also pointing to the accounts ip address. I want to stop the server from serving anything to the "other" domain.

All resolve to /home/person/public_html using one ip address
is resolving to this same ip address and the pages from are being served.

I don't have any control over, just my own apache server.

I want to use htaccess to stop all requests for from serving's pages. Preferably returning a 404 or other more relevant code for "does not exist".
Question by:austinstace
    LVL 57

    Expert Comment

    Well the easy way is not to use .htaccess.  Instead setup a name based virtualhost, create a document root for that named based virutal host and return a web page that says, this is no longer valid, please stop using.

    Now, if you really want to use .htaccess then you would use rewrite and change the URL to one that does not exist.

    Something like:

    RewriteEngine on
    RewriteCond %{HOST}  ^

    As a side note, you can lookup who owns that domain named and contact all/any of the contacts for that domain name inform them they the host name "" is pointing to an IP address that is allocated to you and you would appreciate it very much if they would change it.
    LVL 50

    Accepted Solution

    You can also use mod_rewrite to return a forbidden response:

    RewriteEngine on
    RewriteCond %{HOST}  ^
    RewriteRule  .* - [F]

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Uploading files to the web server has become common part of almost any kind of web application. People use different technologies to solve this, but regardless of the technology used, it is always useful to have some kind of progress indicator shown…
    Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
    Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now