Auto-Notification of Broken Links, Fantastic Pre-Written Anti-Spam .htaccess File!
Recently I’ve been learning a bit about .htaccess, redirecting visitors who come via now-broken links.
To help with this, I inserted a little mailer script into my error 404 page that sends me an email containing the referring URI, the URI the visitor was trying to reach and various other tidbits of information. It works well, allowing me to quickly fix broken links that I would otherwise be unaware of.
It also writes the beginning of a rewrite rule, as if I wasn’t lazy enough.
Here it is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <? php //mail me about this error... $to = "mike(@)pagesofinterest(.)net"; $base = "http://pagesofinterest.net"; $referrer = $_SERVER['HTTP_REFERER']; $requested_page = $_SERVER['REQUEST_URI']; $agent = $_SERVER['HTTP_USER_AGENT']; $ip = $_SERVER['REMOTE_ADDR']; $subject = "Error 404 - $requested_page"; $body = "The page: $requested_page, referred to by $referrer does not exist. Fix this or add a rewrite.\n\nAgent: $agent\n\n"; $body .= "IP: $ip \n\n"; mail($to, $subject, $body, $headers); //append to file: $redirect = "Redirect 301 $requested_page http://pagesofinterest.net/\n"; $filename = "redirects.txt"; $fh = fopen($filename, 'a'); fwrite($fh, $redirect); fclose($fh); ?> |
Use:
sort redirects.txt | uniq > unique_redirects.txt
In a terminal to get a smaller file containing only unique broken links.
One problem was the sheer volume of messages I was getting. I did some research, and it seems this site has become the target of spammers. After a bit of googling on how to discourage this, I came across the best thing a newb could hope for: a perfect, commented example. Aaron Logan has graciously made his .htaccess file available to the world. It handles bad user agents, known bad IP’s, and keywords in referrer URI’s. It is gold.
You can get your own copy of it here: best anti spam .htaccess file.
Thanks Aaron!
Like this post? Move it on along with:
Email |
delicious |
Digg |
Tweet |
Reddit |
Newsvine |
Furl |
Google |
Stumble |
HaoHao
| Trackback: |
Related posts:
- Exec-php and WP-Syntax Caveat Exec-php was attempting to execute the line below, when there was no whitespace between ...
- PHPBB3 Anti-Spam Registration Question Scroll to comments I administrate a few PHPBB3 forums, and recently noticed one had a BIG spam problem. I had naively assumed that PHPBB3’s version of CAPTCHA would stop the bots at the gate – oops. Manually deleting 100’s of spam accounts from my forum wasn’t fun. Determined to prevent this from happening again, I [...]...
- Prevent Wordpress’ .htaccess From Effecting Certain Directories This really frustrated me. To ensure my next bout of horrid frustration isn't caused by the same problem I'm documenting the solution here:...
- WP-Blog Proves that Dreams *Can* Come True The days of staring jealously at the Wordpress crowd have ended. No more shall we scroll longingly down the lists of available Wordpress plugins, wishing they were ported to RapidWeaver....
- Twitter Tools Post From Sidebar – Blog in Different Directory Fix I joined Twitter yesterday, and installed the Twitter Tools plugin....





























Recent Comments
Installing Jdownloader In Ubuntu
Thank You!!!!
It works like a charm!!!!!!!!!!!!
Tue, 05 Jan 2010 13:02:35 +0000
Arrived In Shanghai
Done, look left!
Sun, 03 Jan 2010 15:37:03 +0000
Arrived In Shanghai
Hi :)
I'll see what I can do!
Sun, 03 Jan 2010 14:23:07 +0000
Arrived In Shanghai
Hi Mike. It would be very useful to have the time date and weather conditions in Shanghai, on your site. Be seeing you soon. Love NZMum.
Sat, 02 Jan 2010 23:30:41 +0000
Js Kit Comments Correct Usage Of The Permalink And Path Attributes
I think it could be better
Thu, 31 Dec 2009 09:01:44 +0000