fafa
fafa

Reputation: 107

.htaccess deny access to all except one specific file

I have this rule in my root .htaccess file:

# DENY ACCESS TO EVERYTHING INSIDE PHP DIRECTORY
RewriteCond %{HTTP_REFERER} !^http://(www\.)?someurl [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?someurl.*$ [NC]
RewriteRule ^php - [F]

It denies access to all files inside the "php" directory if accessed outside my server.

How to add one specific file exception, let's call that file "_sharer-socnets.php" using above logic of RewriteCond / RewriteRule?

Upvotes: 2

Views: 66

Answers (1)

anubhava
anubhava

Reputation: 785128

To deny all but one file you can use this rule:

# DENY ACCESS TO EVERYTHING INSIDE PHP DIRECTORY
RewriteCond %{HTTP_REFERER} !^http://(www\.)?someurl [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?someurl.*$ [NC]
RewriteCond %{REQUEST_URI} !/_sharer-socnets\.php$ [NC]
RewriteRule ^php - [F,NC]

Upvotes: 2

Related Questions