Marko Anastasov wrote this on June 26, 2009
Redirecting from the old blog
Initially we started with a Wordpress site on a subdomain for our blogging. Now that we’ve moved to our fork of Enki, when shutting down the old one it would be wise to set up URL redirection to here. That’s of course what mod_rewrite is for.
The trick is not to attempt to put any such global rewrite rule in your Rails application’s .htaccess
file (ah, remember the days when Passenger didn’t play well with mod_rewrite?), but in the vhost configuration file (the one in /etc/apache2/sites-available/
).
Fortunately the URLs look pretty much the same, and all it takes is a subdomain to directory kind of redirection, so it doesn’t involve a complex rule. Here’s what it looks like:
<VirtualHost *> ServerName www.renderedtext.com ServerAlias renderedtext renderedtext.com DocumentRoot /var/enki/public RewriteEngine On RewriteCond %{HTTP_HOST} ^blog\.renderedtext\.com [NC] RewriteRule ^(.*)$ http://renderedtext.com/blog$1 [R=301,L] </VirtualHost>