I need to block an IP in htaccess

9 replies
Hi guys
I have a Wordpress blog where I would like to block a specific IP address for accessing. I believe it is possible to do that in the htaccess.
Anyone that can help me with the syntax for doing that?
#block #htaccess #wordpress
  • Profile picture of the author Kingfish85
    Try here: https://www.google.com/search?hl=en&....1.qko-FlzQwFw

    If you are using cPanel, there is a built in IP Deny Manager to do this..
    Signature

    |~| VeeroTech Hosting - sales @ veerotech.net
    |~| High Performance CloudLinux & LiteSpeed Powered Web Hosting
    |~| cPanel & WHM - Softaculous - Website Builder - R1Soft - SpamExperts
    |~| Visit us @veerotech Facebook - Twitter - LinkedIn

    {{ DiscussionBoard.errors[7280756].message }}
  • Profile picture of the author Mkj
    Originally Posted by Techwork View Post

    Hi guys
    I have a Wordpress blog where I would like to block a specific IP address for accessing. I believe it is possible to do that in the htaccess.
    Anyone that can help me with the syntax for doing that?
    This is the code I use:

    Code:
    order allow,deny
    deny from 82.193.109.248
    allow from all
    I have that at the beginning of my htaccess file. Just replace the above ip address with whatever one you want to block. If you want to add more then just put another line in like this:

    Code:
    order allow,deny
    deny from 220.181.141.65
    deny from 82.193.109.248
    allow from all
    and so on.

    If you want to block a range of ip addresses you can do so like this:

    Code:
    order allow,deny
    deny from 220.181.141.
    deny from 82.193.109.
    allow from all
    The above will block all the ip addresses that are using the same as above but end in whatever 1 - 3 digits. Lots of spammers use this method to throw loads of ip addresses at a site.

    Works fine for me.
    {{ DiscussionBoard.errors[7281026].message }}
    • Profile picture of the author Jr180180
      Do it with style... Direct them somewhere else

      Code:
      RewriteEngine On
      RewriteCond %{REMOTE_ADDR} 127.0.0.1
      RewriteRule (.*) http://google.com [R]
      Replace the URL and the IP you see above with the one that you'd like to redirect. Keep in mind, this simply redirects them if they try to access your site.

      I'll explain.

      Line 1: Turn the engine on
      Line 2: Only if the remote address that access this server is 127.0.0.1, then continue with the next line.
      Line 3: redirect to Google.com

      Now you have two options.
      Signature

      Sharing the love!

      Easy-to-Install Wordpress Plugin - SMS Points System
      Get started on DigitalOcean with DOCasts!

      {{ DiscussionBoard.errors[7281802].message }}
      • Profile picture of the author basscat
        Originally Posted by Jr180180 View Post

        Do it with style... Direct them somewhere else

        Code:
        RewriteEngine On
        RewriteCond %{REMOTE_ADDR} 127.0.0.1
        RewriteRule (.*) http://google.com [R]
        Replace the URL and the IP you see above with the one that you'd like to redirect. Keep in mind, this simply redirects them if they try to access your site.

        I'll explain.

        Line 1: Turn the engine on
        Line 2: Only if the remote address that access this server is 127.0.0.1, then continue with the next line.
        Line 3: redirect to Google.com

        Now you have two options.
        I like the way you think! :p
        {{ DiscussionBoard.errors[7286479].message }}
    • Profile picture of the author y8y8
      Originally Posted by Mkj View Post

      This is the code I use:

      Code:
      order allow,deny
      deny from 82.193.109.248
      allow from all
      I have that at the beginning of my htaccess file. Just replace the above ip address with whatever one you want to block. If you want to add more then just put another line in like this:

      Code:
      order allow,deny
      deny from 220.181.141.65
      deny from 82.193.109.248
      allow from all
      and so on.

      If you want to block a range of ip addresses you can do so like this:

      Code:
      order allow,deny
      deny from 220.181.141.
      deny from 82.193.109.
      allow from all
      The above will block all the ip addresses that are using the same as above but end in whatever 1 - 3 digits. Lots of spammers use this method to throw loads of ip addresses at a site.

      Works fine for me.
      this is correct way to prevent ip by htaccess
      {{ DiscussionBoard.errors[7281952].message }}
  • Profile picture of the author Techwork
    Hi guys.
    Thank you for the feedback. I have been able to make it work to block the user that have been trying to hack my blog the last couple of weeks :-)
    {{ DiscussionBoard.errors[7283965].message }}
  • Profile picture of the author innerbot
    I'm sure there are also a number of WP Plugins that will provide you with this functionality... A quick google search turned up this one:

    WordPress › IP Ban « WordPress Plugins

    No need to go mucking about in your .htaccess... Unless you want to of course :-)
    {{ DiscussionBoard.errors[7284127].message }}
    • Profile picture of the author Techwork
      Originally Posted by innerbot View Post

      I'm sure there are also a number of WP Plugins that will provide you with this functionality... A quick google search turned up this one:

      WordPress › IP Ban « WordPress Plugins

      No need to go mucking about in your .htaccess... Unless you want to of course :-)
      There is a plugin for everything in Wordpress isn't there? In this case I prefer a couple of lines in my .htaccess file. I try to keep my number of plugins to a minimum. Plugins need to be patched and too many plugins are slowing down my blog. But thank you for sharing the info anyway. It might be a better solution for other people that do not feel safe editing the .htaccess file themselves.
      {{ DiscussionBoard.errors[7318739].message }}
  • Profile picture of the author Kingfish85
    OP - The reason why I suggested blocking IP's either in your control panel at the server level or at the firewall level is because using htaccess is not fool proof; there are ways around it. Also, if the user agent happens to drop the string, all those lines in the htaccess become useless.

    Just keep in mind that if someone really wants to get in, htaccess is not going to stop them..
    Signature

    |~| VeeroTech Hosting - sales @ veerotech.net
    |~| High Performance CloudLinux & LiteSpeed Powered Web Hosting
    |~| cPanel & WHM - Softaculous - Website Builder - R1Soft - SpamExperts
    |~| Visit us @veerotech Facebook - Twitter - LinkedIn

    {{ DiscussionBoard.errors[7286501].message }}

Trending Topics