Vote Charlie!

Handling 404 errors in Movable Type

Posted at age 27.

You can of course handle page not found errors entirely outside Movable Type by doing nothing or creating a static error page and pointing to it with your web server’s ErrorDocument or similar directive.

Or, you can make use of a fancy plugin called Clean Sweep by Byrne Reese and Dan Wolfgang that logs errors and allows you to redirect them to their correct pages. It also attempts to guess the correct URL if the attempted URL matches the basename of an existing entry, which is pretty slick.

I set this up today on my website, and after a few fixes, got it working splendidly:

  1. Added support for HTTPS websites
  2. Fixed bug preventing logging new failed pages
  3. Enhanced redirect with query parameter to let me display the failed URL for end user

(If those links ever break, 1 and 2 should at least be available in this pull request.)

Then, on my 404 page itself, I threw this basic code to allow the end user to contact me by Twitter:

You tried to visit:

<code><?php echo 'https://votecharlie.com/'.htmlentities($_GET['target']); ?></code>

Unfortunately that does not exist. This could be my fault, or someone else's. But hey, what politician would even admit he could possibly be at fault? That's a good thing, right?

<script type="text/javascript" async src="//platform.twitter.com/widgets.js"></script>
<a href="https://twitter.com/intent/tweet?via=cng&text=I was looking for &url=<?php echo htmlentities('https://votecharlie.com/'.urlencode($_GET['target'])); ?>">
  <img src="https://g.twimg.com/dev/documentation/image/Twitter_logo_blue_16.png" width="16" height="16">
  Let me know my site is broken!
</a>