[Linux] How to secure an URL address from Apache?

If you want to make certain urls from a website inaccessible to other visitors, follow the steps.

Allow only certain IPS to access this url for example: incvice.com/admin.

From the config file of Apache, add this code.


Order deny,allow
Deny from all
Allow from 82.238.21.30
Allow from 11.22.33.44

Be sure to add your IP, you can find what is your IP on the Internet.
All other IPS that will visit incvice.com/admin will get a restricted error message instead of the admin page.

Save the apache config file and restart apache using this command: $ service apache2 restart

Another method is to only allow the access by using authentication:

First step: Add inside apache’s config file this code:


AuthUserFile /var/www/htpasswd/.htpasswd
AuthName Password Protected Area
AuthType Basic
Require valid-user

Second step: create the htpasswd by executing this command.

$ htpasswd -cm /var/www/htpasswd/.htpasswd user

Save and restart apache by using this command: $ service apache2 restart

ADD A COMMENT: