Automate 404 discovery, the easy PHP way.

For this edition of Quick Codes I am sharing how to send an email whenever someone lands on your 404 File Not Found error page. I found this on CSS-Tricks.com’s 404 Best Practices post and had to share it. Just to clarify this code has not been vetted to ensure security or that it works perfectly, but sometimes it gets the job done just fine. This code is PHP, but the idea could be adapted to any language. For more good ideas don’t forget to check out my post Better 404 error pages by design.

mail("name@domain.com", "404 report", $_SERVER['REQUEST_URI'], "From: example@domain.comn");

UPDATE:

Thanks to a recent comment by Thomas Scholz, I added the addslashes() function to escape any funny stuff inside the request url.

mail("name@domain.com", "404 report", $_SERVER['HTTP_HOST'] . addslashes($_SERVER['REQUEST_URI']), "From: example@domain.comn");

And I also found a good piece of code on codex.wordpress.org which is an excellent resource. View the full page with example code here: Creating an Error 404 Page « WordPress Codex

Twitter “lists” are like groups for twitter

Aside

So today I logged onto twitter and was presented with a message informing me I was part of a small beta group that gets to test their new “lists” feature. The new lists are basically groups of people that make it easier to browse a specific subset of people. This is great if you are following a few thousand people and are interested in many topics.

The first list I made can be found here and is some of my favorite web designers and developers, which is why I called the list web people. This will make it much easier for people to stay up to date on friends, family, and interesting people in specific niche’s or industries.

One of the coolest thing about lists is that you can follow them separately than the person who made the list. Also you don’t have to follow 20 people in a certain topic, you can just find a list and follow that. You can also find out which lists you are on and following by going to a url like this https://twitter.com/montanaflynn/lists/memberships and replacing montanaflynn with your or anyone else’s twitter name. That is a great way to find lists that you are interested in as well. Go to my lists page: Montana Flynn’s Twitter Lists

Their is certainly more work that could be done, like an eaiser way to add people to list instead of searching for each person. Also their should be a list search in order to find good lists that you may be interested in. In the meantime a great place to start finding list is on Listorious which brings the most popular lists to you and has an awesome UI and features such as tags and search built in.

Groups for twitter has arrived with the new lists feature.

Twitter List Beta

a twitter list for web designers and developers

Did you get invited to test this beta feature? Do you have any opinions on if the lists is a step in the right direction of if twitter should focus on other improvements? I would love to hear comments from you, all and you can even log in through twitter in the comments below!

How To: use your .htaccess file

Aside

So one of the things I have been experimenting with lately is the .htaccess file.   I had heard of it before but never implemented it into my websites.   That changed when this blog was getting blasted by spam “bots” that were eating up my bandwidth!  Last month I had 2GB of bandwidth consumed by the “bots”. Also I had heard of using this file to make your url always have a www. at the beginning even if the user doesn’t type it. Then their are also ways to redirect visitors in case you change your file directory. So I thought I would share what I learned!

# This allows you to redirect your entire website to any other domain
Redirect 301 / http://example.com/

# This allows you to redirect index.html to a specific subfolder
Redirect /index.html http://example.com/newdirectory/

# Redirect old file path to new file path
Redirect /olddirectory/oldfile.html http://example.com/newdirectory/newfile.html

# Prevents directory listing
Options -Indexes

# To redirect all users to access the site WITHOUT the www. prefix,
# (http://www.example.com/… will be redirected to http://example.com/…)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://mt-example.com/$1 [L,R=301]

# To redirect all users to access the site WITH the www. prefix,
# (http://example.com/… will be redirected to http://www.example.com/…)

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

# To block all the bad “bots”

RewriteCond %{HTTP_REFERER} ^-?$ [NC]
RewriteCond %{HTTP_USER_AGENT} ^-?$ [NC]
RewriteRule .* – [F,L]

Tr.im url shortener with analytics

Aside

Tr.im is a url shortening service like www.tinyurl.com except it is makes REALLY small url’s! It also has built in anaylitcs, bookmarklets, and the ability to add the tr.im’d urls directly to twitter!

Lets take a look at the great UI:

picture-9

You do not need an account although it is so simple to set up an account, it took me less than 30 seconds, you might as well. Once you have your account set up you can begin using the service with analytics. Its relatively simple you paste a long url and press tr.im and it returns a small url to post in social networks and microblogs like chi.mp and twitter. The coolest thing about it that you can measure your impact through the visitors analytical data such as OS, browser, referral pages, and more:

picture-10

I switched to tr.im because of the API and bookmarklets they have available, when you click on a tr.im bookmarklet, for example, it grabs the website address you are at, and gets a tr.im URL for it, automatically. It can even automagically send the trimmed url to twitter! Bookmarklets are supported in either Firefox, Safari, Chrome or Opera. If you use IE, perhaps you should switch! Today!

Of course their are many more url shortening services, perhaps you would like to check them out as well, here are the best ones:

  1. is.gd
  2. ow.ly
  3. zi.ma
  4. nn.nf
  5. rt.tc
  6. cli.gs