Ioan Ioan - 5 months ago 44
Apache Configuration Question

Blocking the entire site excepting one folder with htaccess

I'm new to Apache and htaccess.

I want to allow only one IP to see the entire site, but for the rest of the people to have all files returning 403 except one folder and his files.

I already tried this and it's working only for the index, and not for all the files from the folder

RewriteEngine On
RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxx
RewriteRule .* - [L]
RewriteCond %{REQUEST_URI} !"/freedom"$ [NC]
RewriteRule ^(.*)$ - [R=403,L]


You can use:

RewriteEngine On

# allow one IP access everything
RewriteCond %{REMOTE_ADDR} xxx\.xxx\.xxx\.xxx
RewriteRule ^ - [L]

# if request is not for /freedom/... then return 403 
RewriteRule !^freedom(/.*)?$ - [F,L]