• 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

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

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

  • How to Run WP-CLI on Windows
  • Get an array of variation IDs for a WooCommerce product
  • Check and delete orphaned post meta in WordPress
  • Block an IP address from accessing your site
  • Using WordPress Debug Constants

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