WordPress

Securing WordPress Admin with .htaccess

One of the easiest ways to help secure your WordPress installation from unauthorized access is to only allow specific IP addresses to access the admin panel. One of WordPress’ larger security targets is the platform’s inability to set a custom administrative URL, by default all installations are located at /wp-admin. Thankfully we can easily handle this by adding a few lines of code to .htaccess.

FTP onto the server containing the WordPress site and navigate to the website root and then into the wp-admin directory.

{{installation root}}/wp-admin

If a .htaccess file exists in this directory right click on the file and select edit. Otherwise, create a new file and name it “.htaccess”. Once the file is open for editing add the following to the beginning of the file replacing xxx.xxx.xxx.xxx with your IP address:

AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "Admin Access Control"
AuthType Basic
<LIMIT GET>
order deny,allow
deny from all
# whitelist IP address
allow from xxx.xxx.xxx.xxx
</LIMIT>

Note: The filename starts with a period (full-stop) and then htaccess all in lower case.

If you would like to whitelist more than one IP address you can simply add more lines of “allow from xxx.xxx.xxx.xxx” as follows:



AuthUserFile /dev/null
AuthGroupFile /dev/null
AuthName "Admin Access Control"
AuthType Basic
<LIMIT GET>
order deny,allow
deny from all
# whitelist IP address
allow from xxx.xxx.xxx.xxx
allow from xxx.xxx.xxx.xxx
allow from xxx.xxx.xxx.xxx
</LIMIT>

To obtain your public-facing IP address you can simply go to www.google.com and in the search type “what is my IP?” and it will return your current address.

Advertisement

Hans-Eirik Hanifl

Hans-Eirik Hanifl is a forward thinking e-commerce and marketing consultant. As an advocate for the free exchange of knowledge, he founded E-Commerce Gorilla as a place where like-minded individuals can ask questions and share their expertise on practical solutions in the area of e-commerce and marketing. He is the owner of TRM Marketing and an avid supporter of the open source community.

Leave a Reply

Advertisement
Back to top button
Sign up to the E-Commerce Gorilla newsletter for updates & special promotions.
Join Our Newsletter
SUBSCRIBE
We value your privacy and protect your information like our own. Unsubscribe at anytime.