• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP Bitz

A curated collection of code snippets for WordPress

  • Home
  • About
  • Blog
  • Code Snippets
You are here: Home / WordPress Development Tips / Block an IP address from accessing your site

Block an IP address from accessing your site

WordPress Development Tips · June 19, 2020

This post brought to you by RocketGeek, ButlerBlog, and the following:

 

Generally, you can use your .htaccess file to block access to your site from certain IP addresses. This can be an effective method of blocking attacks that originate from a specific location.

If you are running WordPress, you most likely already have an .htaccess file in your site’s directory structure. If not, you’ll need to create one.

To create a new .htaccess file, just make a new file and call it “.htaccess”. Note the dot at the beginning and nothing at the end.

To block an IP using .htaccess, add the IP to your file as follows:

Deny from 123.123.123.123

If you need to block a range of IPs, you can do that like so:

Deny from 123.123

Block multiple IPs by providing a list of IPs to block (separated by spaces, not commas):

Deny from 123.123.123.123 222.222.222.222 333.333.333.333

You can get more advanced than that with regular expressions and other .htaccess tricks. Check out the following article for more advanced examples:

How to Block IP Address with .htaccess

Filed Under: WordPress Development Tips Tagged With: htaccess

Chad Butler

This post brought to you by RocketGeek, ButlerBlog, and the following:

 

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Join for free!

Get free code snippets, WordPress best practices, and practical Content Marketing advice from seasoned WordPress expert Chad Butler (butlerblog):

Recent Posts

  • Bitnami WordPress Autoptimize cannot write to the cache directory
  • Create and delete WordPress sites in XAMPP with a batch file
  • How to fix “Error: MySQL Shutdown Unexpectedly” in XAMPP control panel
  • Fix missing Customizer in WordPress 6
  • Use Proofy.io API to validate WordPress registrations

Copyright © 2023 · Maker Pro on Genesis Framework · WordPress · Log in