Software, Development, and WordPress

Setting Up a Rails Application on a Subdomain of WordPress Site

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):

~/app/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.

8 Comments

  1. gunnard

    nice tips, and def make a .bak of the .htaccess!

    • Tom

      yes, definitely.

  2. John (TentBlogger)

    this theme looks so hawt.

  3. Jared Erickson

    notice he said “looks hot” not “coded beautifully” …. :-)

    • Tom

      Can’t put hot skin on a nasty skeleton, though.

  4. τα βλαχικα βαρη

    When I originally commented I seem to have clicked on the -Notify me when new comments are added- checkbox and now whenever a comment
    is added I receive 4 emails with the same comment.

    Perhaps there is an easy method you are able to remove me from that service?

    Kudos!

    • Tom McFarlin

      Shoot me an email with the email address that you’re receiving multiple emails and I’ll look into the database and remove the entry :).

Leave a Reply

© 2020 Tom McFarlin

Theme by Anders NorenUp ↑