« Back to blog

Blog: CakePHP Redirects for legacy URLs

Graham Weldon

03 February, 2009

If anyone has a more elegant solution than this, perhaps involving routing, let me know. Since the launch of this new site on the weekend, I have been serving up plain html to old RSS aggregate sites. The reason is that I was previously using WordPress as my blogging engine, and the url was: /blog/?feed=rss2 which cake prompty served from the route handling the /blog/ path.

That just won't do, so I created the following, which performs 301 permanent redirects for requests to that old URL, from within my new blog posts controller.

if (@$this->params['url']['feed'] == 'rss2') {
		'controller' => 'blog_posts',
		'action' => 'index',
		'ext' => 'rss'), 301);

Now, all requests are being redirected to the blog_posts controller, and the automagic of parseExtensions is serving up the RSS content.

Migrating your website to a custom build can be painful, especially if you are well established, and already have a collection of backlinks and referral traffic. I hope the above is useful to someone out there.