Setup basic auth on wp-admin directory

Last Updated at : February 4, 2018 By - Usama Muneer | 1214

    If you’re running a WordPress website or blog, its always a good practice to setup some sort of security for your admin area & restrict access for smart users.

    The most basic thing to do is setup a basic auth for your wp-admin directory and wp-login.php so that none can pass through except for the authors or users who are authorised.

    Step # 01 – Create .htpasswds file

    Right in your document root, create an empty .htpasswds file, like so

    <Document-root> touch .htpasswds

    Step # 02 – Generate .htpasswds contents

    Head over to this online tool and generate your .htpasswds contents & paste the output in your .htpasswds from step 1.

    Step # 03 – Create .htaccess file for wp-admin

    Inside of your wp-admin directory, create .htaccess file and paste the following code

    AuthUserFile /path/to/your/root/.htpasswds
    AuthType basic
    AuthName "Restricted Resource"
    require valid-user
    # This is the whitelisting of the ajax handler
       <Files admin-ajax.php>
         Order allow,deny
         Allow from all
         Satisfy any
       </Files>

    That’s it. save the file, head over to the browser and try accessing your wp-admin area, it now should ask for your username & password for authentication.

    blog user
    Usama Muneer

    A web enthusiastic, self-motivated & detail-oriented professional Full-Stack Web Developer from Karachi, Pakistan with experience in developing applications using JavaScript, WordPress & Laravel specifically. Loves to write on different web technologies with an equally useful skill to make some sense out of it.

    Related Posts

    Inspired from Laravel's router, lets build our very own PHP's router for managing our endpoints well for our next PHP project.

    Another #LaraconUS in the books & It was the 6th instalment of #LaraconUS happened at Chicago with full swing & we got a lot to learn this time with exceptional line of speakers and never-ending community support by fellow Artisans

    Laravel is one of a famous and widely used PHP framework which is growing with immense pace since its version 4.2. Learning Laravel & Setting up your application locally is not much of a difficult task but when it comes to deployment, developers often find it a bit tricky to handle.

    There are several PHP frameworks for a web development project. Among them Laravel is regarded as the best open-source PHP web framework.