htaccess to deny access by requested URL

Posted on 2009-04-20
Last Modified: 2013-12-16
I have a virtual host set up on my apache web server. This redirects to a folder as such: /var/www/html/site2 this is <>

The default Virtual host points to /var/www/html/ as the root. This is <>

I want to stop anyone using <>  from accessing the site2 directory

This is mainly just to make sure that our other customers don't stumble across our hosted customer's site tied to our domain name.

I tried many variations of the following code with no luck, I also tried {REQUEST_URI} with no luck.

I could recreate the default virtual host into another directory, but because of many of the internal programs and scripts, this would cause a lot of extra work.

Thanks in advance for your time.
Options +FollowSymlinks

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www\.oursite\.com$ [NC]

RewriteRule (.*) - [F,L]

Open in new window

Question by:jabberwok_e
    LVL 27

    Expert Comment

    Did you place the code into a

    <Directory /var/www/html/site2>
    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.oursite\.com$ [NC]
    RewriteRule ^ - [F,L]



    Author Comment


    I just have it in a .htaccess file in the /var/www/html/site2 directory.

    Should the <directory> tags be in the httpd.conf file or .htaccess file in the root directory?

    LVL 27

    Accepted Solution

    > Should the <directory> tags be in the httpd.conf file


    > I just have it in a .htaccess file in the /var/www/html/site2 directory.

    May be the AllowOverride directives are set in a way that overriding "FileInfo" is not permitted in .htaccess files? Anyway, if you have access to the httpd.conf, you shouldn't use .htaccess files (performance reasons).

    Author Comment

    Fantastic! it works exactly as needed!

    Thank you very much.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Cloud file services can fill many different roles for your business. Often, the use of cloud file services begins with employees using consumer products, like Dropbox, to share files with customers and each other. While sync-and-share can be an effe…
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    779 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

    14 Experts available now in Live!

    Get 1:1 Help Now