.htaccessdirectorydirectory-permissions

Allow directory access to certain IP addresses


I am working on a website and I need a directory to be disabled to the public.

I was wondering if there is a way I can redirect all users to a web page, unless I specify a few IP address that are allowed to enter the directory

I don't know much about the .htaccess file, however could I use that to do this?

Thanks Peter


Solution

  • You can do this simply with the following code.

    order deny,allow
    deny from all
    allow from x.x.x.x
    allow from x.x.x.x
    allow from x.x.x.x
    

    Using the above lines, it's important that you keep the order the same. Denying from all before allowing from specific addresses will allow access to only a few IPs while allowing before denying will deny access to all.

    For more information, try searching google for htaccess deny/allow commands.