3rd January 2012 - 4 minutes read time
I'm always writing bits of script to test things out and I thought that I would start making a record of them in case I need them in the future. This is a little script that will loop through the contents of a text file and validate that a bunch of 301 redirects point to the place they are meant to point to. This script assumes that the redirects are already in place on the server, but this is what I was testing. Here the format of the redirects text file.
http://www.exmaple.com/old_page http://www.exmaple.com/new_page
http://www.exmaple.com/nother_old_page http://www.exmaple.com/another_new_page
The script below loads in this file and loops through it using the PHP function get_headers() to test that the first URL redirects to the second. If any problems are found then the line number and the problem is reported on.