Avoiding subdomain feed redirects
September 11th, 2010 by David Bradley >> No Comments
Regular visitors will be aware that I am polygamous when it comes to blogs. As well as the Sciencetext Tech Talk blog, I also running a science site (Sciencebase.com), a photo site (ImagingStorm.co.uk) and various others.
I recently moved Imaging Storm from the original web host to the same hosting as Sciencebase.com, which required creating a subdomain on Sciencebase.com. Things went fairly smoothly, including the import of the WordPress MySQL database from the original web host to the subdomain. But, there was one problem. The Imaging Storm RSS feed was redirecting to the Sciencebase.com feed instead of displaying posts from the photo blog. Annoying to say the least.
I chatted to the web host tech support, who were very helpful and eventually we tracked the problem down to a redirect in the Sciencebase “.htaccess” file that was meant to help me offer readers a short link to that site’s feed – http://sciencebase.com/feed that would redirect to the full feed automatically. Unfortunately, because this redirect was in the root of the domain it was also catching http://imagingstorm.co.uk/feed and simply redirecting that to the Sciencebase feed too.
The solution was to remove the redirect, but then I wouldn’t have my nice simply Sciencebase feed link, which would be irritating. So, a conditional redirect is what was needed. After much searching and hacking, I pulled together a neat bit of code that would redirect /feed to the Sciencebase feed but not if the /feed was a “subfolder” of Imaging Storm. Now all’s well, as far as I can tell.
Anyway, this is what the .htaccess Apache code should look like if you have the same problem with a self-hosted blog in a subdomain of your main blog and things are redirecting incorrectly:
<IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC] RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC] RewriteCond %{HTTP_HOST} !^imagingstorm\.co\.uk [NC] RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feedproxy.google.com/feed-name [R=302,NC,L]</IfModule>
Obviously, you’d need to substitute your own feed-name and subdomain and this particular piece of code applies if you are using Feedburner to render the feed.

"Deceived Wisdom: Why What You Thought Was Right Is Wrong" from David Bradley. Available now on 

