Skip to content

random linux notes

Tag: mod_rewrite

wp-login.php

Defending this script has become my biggest nightmare in the last few months. Black listing mostly works for denial of service from poorly written bots. I blacklist amazon, web hosts, many foreign countries, without hesitation, not just one IP but their whole allocation.

Fail2ban was able to block some portion of these but isn’t very flexible or robust so it often missed the boat.

I’d been struggling to keep my server load at reasonable levels due to the constant barrage of hits. When the bot writers got more clever about number of hits per IP per time these methods quickly failed to stem the tide.

Fortunately the ultimate defense is to require a simple webserver password to access wp-login.php. Implementing the following took my sever load back to normal overnight.

# this blerb should work in a .htaccess file or under a virtual host portion of an apache
# config file
#
# Protect wp-login
<Files wp-login.php>
AuthUserFile /home/site_name/.htpasswd
AuthName "Private access"
AuthType Basic
require valid-user
</Files>
#use htpasswd or website tools to create the above .htpasswd file

However many of the wordpress sites on my box use wp-login.php to handle authentication/authorization for private portions of the sites so distributing a second password to all the users didn’t make sense. So a clever use of mod_rewrite was needed for those other sites.

WARNING: You might not be happy if you use the below without adding an additional rule as all your attempts to login will just redirect back to the login page.

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteCond %{REQUEST_METHOD} POST
        RewriteCond %{REQUEST_URI} .(wp-login).php*
        RewriteRule (.*) http://%{SERVER_NAME}/$1 [R=301,L]
</IfModule>
Author rlnPosted on November 4, 2015Categories rlnTags .htaccess, .htpasswd, blacklist, fail2ban, mod_rewrite, wordpress, wp-login.phpLeave a comment on wp-login.php

Recent Posts

  • HP M29w linux – ubuntu 24.04
  • What I Wish Someone Told Me About Postgres – for posterity
  • mailinabox
  • journalctl
  • get your pages indexed with google search console and google cloud

Recent Comments

  1. djbdns dnscache | random linux notes on new vps with centos 6 for tinydns secondary
  2. oldirtdog on grub2 help for kernel upgrade on Ubuntu 12.04 domU on XCP

.htaccess 18.04 20.04 bash canon centos6 dell djbdns dnscache grub2 julia linux localhost luks mysql netflix linux netgear nvidia paravirtualize pdf perc5i perc 6 perc6 postgres post install printer psql pulseaudio qmail raid raid 1 recovery red vegetable wrt software ssh ubuntu ubuntu 12.04 update usb wordpress wrt xapi xcp xe xen xenserver 7.0

random linux notes Proudly powered by WordPress