If you have an established blog and have readers who subscribe to your feed you’ll likely loose them when you migrate to Wordpress and your RSS feed URL changes. Wordpress feed look like http://www.mysite.com/blog/feed/ if you’re blog is at http://www.mysite.com/blog/. My previous blog software’s RSS feed url looked like http://www.mysite.com/blog/?wl_mode=rss2. I didn’t have too many subscribers, but there were a few and I didn’t want to leave them hanging so I set about using a 301 permanent redirect to solve this problem.
Fixing this is pretty straightforward, just a couple of lines of code. For me this the following placed near the top of index.php does the trick.
if ($_GET['wl_mode'] == 'rss') {
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://" . $_SERVER['SERVER_NAME'] . "/blog/feed");
exit();
}
It looks for the get parameter wl_mode to be ‘rss’. If wl_mode is defined and equal to ‘rss’ it sets two headers in the response and then exits. The first tells the client to redirect and that the redirect is permanent. The second gives the location to redirect to, the server name of the request, from the variable so that it matches whatever hostname the request was made to and the path of Wordpress’s RSS feed, ‘/feed’. The ‘/blog’ is where Wordpress is installed on my site, if your root is Wordpress you’d just have ‘/feed’.
What if your old url wasn’t wl_mode=rss. If it’s a different parameter or set of parameters you’d just swap them out. What if the old feed is not a parameter, but a URL/path? Something like the snippet below should be useful there.
if ($_SERVER['REQUEST_URI'] == '/blog/old/feed/path') {
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://" . $_SERVER['SERVER_NAME'] . "/blog/feed");
exit();
}