Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

htaccess access to file by ip range

Tags:

php

.htaccess

How to allow access to file only to users with ip which are in a range of ip addresses?

For example file admin.php. and range from 0.0.0.0 to 1.2.3.4.

I need configure access to only ONE file not to directory.

like image 217
Mirgorod Avatar asked Feb 18 '11 14:02

Mirgorod


People also ask

How do I allow only certain IP addresses?

How to manage access with an IP Manager? Go to Hosting → Manage → IP Manager: There, you will be able to find 2 options: add IPs to allow and block access to your website: Just add an IP you wish to create rules for, leave a note (optional) and click on Add.

How do I restrict IP address in htaccess?

Step 1: Generate the Country's IP Addresses Select the countries you want to block or allow. On the Select Format section, choose Apache . htaccess Deny or Apache . htaccess Allow.

How do I block an IP address from a certain country?

Blocking a country couldn't be easier. Just log in and go to 'Threat Control', then where it says 'Add custom rule', start typing the full country name and then click it from the dropdown list. Click the big red 'Block' button and you're done!


1 Answers

Just add a FilesMatch or Files directive to limit it to a specific script.

The following would block acces to all scripts ending in "admin.php" :

<FilesMatch "admin\.php$">     Order deny,allow     Deny from all     Allow from 10.0.0.0/24 </FilesMatch> 

The following would ONLY block admin.php :

<Files "admin.php">     Order deny,allow     Deny from all     Allow from 10.0.0.0/24 </Files> 

For more information refer to the apache docs on Configuration Sections.

like image 107
wimvds Avatar answered Oct 01 '22 08:10

wimvds