WordPress Tip – Redirect to Main Page on 404

If you’re using the Postalicious WordPress plugin to post your del.icio.us links to your blog, you might have noticed that it doesn’t always handle the occasional 500 errors from del.icio.us very well, and you end up with a bogus ‘links’ entry on your blog with a link to ‘500 Server Error’.

In itself, it’s not that big a deal; I usually notice the bogus post pretty quickly and just delete it, but, by then, it’s been tweeted by Twitterfeed, pushed to Facebook, and folks have it in their RSS stream, so they hit the ‘links for the day’ link and get the default ‘404 page not found’ message. In fact, if you ever delete a post for any reason, you’re in the same situation – the link is out there, you can’t call it back (even if you go delete it from Twitter and Facebook, it’s still out there somewhere!), and people are going to land on that ugly page.

So, I got thinking… That default 404 page isn’t really good for much… What if I could just send people to the main page of my blog? Well, with a couple of minutes googling I found a useful blog post on the subject and the WordPress docs for get_bloginfo(), and came up with the following replacement for the default 404 page:

<?php
   header("Status: 301 Moved Permanently");
   header("Location: ".get_bloginfo('url'));
?>

You could do fancier things with a JavaScript redirect that shows a ‘page not found’ message then redirects after a few seconds, but I prefer the more direct approach 🙂

Salesforce.com – Two Weeks In

Behind the Cloud
I'm currently reading 'Behind the Cloud'

It’s the end of my second week at Salesforce.com, and I seem to have hit the ground running… A day of orientation, a couple of days working through the Force.com and Chatter developer tutorials, then head down on a guide to Getting Started with the Force.com REST API, published alongside the REST API Developer Preview Webinar last Tuesday (the webinar replay is online now).

The getting started guide featured a sample Java web app that acted as an OAuth 2.0 client, redirecting the user to login at Salesforce.com and obtaining an access token with which to interact with the Force.com REST API. Cool stuff, but there were a couple of questions on the webinar asking how to do the same thing from other languages. It took just a few hours to rework the sample web app, first in Ruby, then in PHP. I’ve also noticed a .NET implementation, by Dan Boris – cool stuff!

I’m commuting up the peninsula about three days a week on Caltrain, which is working out pretty well – there’s a station less than three miles from my house, and I can change to the Baby Bullet in San Jose, with the ride to San Francisco taking about an hour. I actually enjoy the time on the train – I just get my laptop and 3G card out and tap away – in fact, I’m on the train right now, somewhere near Palo Alto. 🙂

So – two weeks in, I’ve published three pieces on *force.com, seen some very cool ISV demos at the second AppQuest judging round, and I’m off to Internet Identity Workshop XI tomorrow. If this sounds like your idea of fun, take a look at the Salesforce.com careers page. Lots of opportunities there, and, if you see something you like, don’t forget to tell them that sent you!