Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Web Servers»Apache»How to Secure Specific URL in Apache

    How to Secure Specific URL in Apache

    RahulBy RahulMarch 5, 20132 Mins ReadUpdated:April 20, 2022

    Sometimes we are required to secure a single URL or a few specific URLs on our site, and all other site URLs keep remain with public access. This is very easy to manage by using directory and file structure in sites. But some frameworks like CakePHP work on routing structure which is different from the directory structure, we can’t secure it on the directory level.

    This article will help you secure a specific URL in Apache. For example a site has a secure area like http://example.com/admin/” and we need that only the authorized users or IP addresses can access /admin/ section.

    1. Setup IP Based Restriction on Specific URL

    First, edit the Apache configuration file and add the below entry in VirtualHost. This will allow /admin URL to 192.168.10.11 or an IP range like 192.168.1.0/24.

    <Location /admin>
      Order deny,allow
      Deny from all
      Allow from 192.168.10.11
      Allow from 192.168.1.0/24
    </Location>
    

    Save the Apache configuration file and restart the apache service using one of the following commands.

    sudo systemctl restart httpd        #On RedHat based systems
    sudo systemctl restart apache2        #On Debian based systems
    

    Let’s try to access your site from any other IP address. Also, check the given IP address in the configuration file.

    2. Setup User Authentication on Specific URL

    You can also enable a login screen for a specific URL in the Apache webserver. To do this, edit the Apache configuration file and add the below entry in the website VirtualHost section.

    <Location /admin>
      AuthUserFile /var/www/htpasswd/.htpasswd
      AuthName "Password Protected Area"
      AuthType Basic
      Require valid-user
    </Location>
    

    Now create new htpasswd file using below command and add a new user.

    htpasswd -cm /var/www/htpasswd/.htpasswd myuser
    
    Output
    New password: Re-type new password: Adding password for user myuser

    Restart the Apache service and access your site URL. It will prompt for login details.

    sudo systemctl restart httpd        #On RedHat based systems
    sudo systemctl restart apache2        #On Debian based systems
    

    Thanks for using this article, I hope this article fulfill your needs. Click here to read more details about apache location directive.

    configure apache to restrict url for specific ip how to secure url in apache IP based restriction for url Password protected url Secure specific url in apache Secure specific url in CakePHP with Apache Secure specific url with Apache secure url Setup IP Based Restriction on Specific URL Setup User Authentication on Specific URL Url protection in apache
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Shrink SQL Server Transaction Log Files using DBCC SHRINKFILE
    Next Article How to Install Postfix on CentOS/RHEL 7/6/5

    Related Posts

    How To Disable HTTP Methods in Apache

    Updated:December 31, 20212 Mins Read

    How to Install and Configure Fail2ban on Debian 11

    3 Mins Read

    How To Secure SSH Server

    Updated:July 24, 20215 Mins Read

    How To Enable Brotli Compression in Apache

    2 Mins Read

    How to Secure GitLab Server with Let’s Encrypt SSL

    2 Mins Read

    X-XSS-Protection – Secure Apache from Cross-Site Scripting

    Updated:August 31, 20202 Mins Read

    3 Comments

    1. Ume on March 14, 2019 6:15 am

      How can we allow certain URLs only, e.g. URLs which starts with /resources , which contains certain word ?

      Reply
    2. Radesh on January 28, 2016 5:41 am

      Very helpful and easy to follow. Thanks Chris!

      Reply
    3. chris on September 17, 2014 1:24 pm

      Thanks for the info. Would really help if you mentioned where the apache config file is located.

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • Filesystem Hierarchy Structure (FHS) in Linux
    • How to accept user input in Python
    • What is difference between var, let and const in JavaScript?
    • What is CPU? – Definition, Types and Parts
    • What is the /etc/aliases file
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.