I just finished deploying a Rails application onto a subdomain of a site that has WordPress installed on the root domain. Unfortunately, WordPress’ htaccess rules made it a little bit more difficult to launch than expected.

Here’s what I did to get Rails and WordPress to play nicely together:

First, I uploaded the Rails app into it’s own directory (assume the application is called my_app):


After creating the subdomain, I created a symbolic link from within the public_html directory of the WordPress installation to the Rails application’s public directory:

ln -s ~/app/my_app/public ~/public_html/my_app

Finally, I added the following two rules to the htaccess file:

RewriteCond %{REQUEST_URI} !^/my_app.*
RewriteCond %{SERVER_NAME} !my_app.domain.com

The final htaccess file looks like this:

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]

RewriteCond %{REQUEST_URI} !^/my_app.*
RewriteCond %{SERVER_NAME} !my_app.domain.com

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Note that if you update the permalinks within WordPress, then this file will be overwritten and you’ll need to correct the changes.