• RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Hey guys, Yesterday I did an interesting server configuration. Actually we had a rails app hosted on server which is using passenger(a.k.a mod_rails). This application can be access by going to http://domain.com . Also we had a wordpress running which could be access by going to http://blog.domain.com.

But, for SEO sake I had to change configuration so that wordpress can be access by http://domain.com/blog instead of http://blog.domain.com/

The problem was if I configure wordpress for http://domain.com/blog and go to this url, the request was handled by rails app because of domain.com virtualhost.

So what I did? I changed apache virtualhost configuration for http://blog.domain.com and http://domain.com as:

<virtualHost *>
    ServerName blog.domain.com

    DocumentRoot /var/www/html/wordpress/
    <directory "/var/www/html/wordpress/">
      Options FollowSymLinks
      AllowOverride None
      Order allow,deny
      Allow from all
   </directory>
 </virtualHost>


<virtualHost *>
    ServerName domain.com
    ServerAlias www.domain.com
    DocumentRoot /var/www/html/domain/current/public
    <directory "/var/www/html/domain/current">
      Options FollowSymLinks
      AllowOverride None
      Order allow,deny
      Allow from all
    </directory>

  RailsAllowModRewrite  on
  RewriteRule ^/blog/?(.*)$ http://blog.domain.com/$1 [P,NC,L]

 </virtualHost>

Also I created a symbolic link to wordpress installation directory under rails public folder(ln -s /var/www/html/wordpress /var/www/html/railsapp/public/blog).

Now remember to change your wordpress address and blog address options to http://domain.com/blog under settings tab of wp-admin section.(Thanks Amit for pointing this out)

I restarted apache and it worked fine. WordPress was running at http://domain.com/blog and rails app was as http://domain.com/.

Update: If you want to change your wordpress permalink structure in account of SEO please change “AllowOverride None” to “AllowOverride All” as shown in image below.

16 Responses so far.

  1. Amit Solanki says:

    Thanks for the post brother.
    ~Amit

  2. Tom Cocca says:

    Thank you for this post. I am having one issue though.

    when I go to http://www.domain.com/blog I get redirected straight the the http://www.domain.com homepage

    However, http://www.domain.com/blog/wp-admin works perfectly fine.

    Any ideas what could be wrong with the setup?

  3. Akhil Bansal says:

    Woh!! it helped me again while setting up rails and wordpress. Good, I wrote a blogpost earlier.

  4. [...] Hosting Rails app and WordPress on same domain(as folder instead of subdomain) | WebOnRails. [...]

  5. sandrar says:

    Hi! I was surfing and found your blog post… nice! I love your blog. :) Cheers! Sandra. R.

  6. Balaji says:

    Nice one, will give it a try.

    Was looking for using opensource rails forums like Beast but I think WP would be a good alternative (esp. with forum plugins in wordpress)

  7. I am the first time on this site and am really enthusiastic about and so many good articles. I think it’s just very good.

  8. Lee says:

    Humm, I followed the directions exactly and I am still getting a 404 when I go to mydomain/blog.

    Any idea what may be going awry?

  9. Lee says:

    I am on Apache/2.2.14 (Ubuntu) and Passenger 2.2.15.

    I added the stuff but I still get a 404. I am however now clearly skirting passenger, as before the 404 page was the one served up by Rails and now it is the apache default.

    Any more ideas?

  10. Lee says:

    Vhost config for the blog:

    <VirtualHost *:80>
    
      ServerName  blog.physicalhearts.com
      ServerAlias blog.physicalhearts.com
    
      DocumentRoot public_html/blog.physicalhearts.com/wordpress
    
    </VirtualHost>
    

    Vhost config for the app:

    <VirtualHost *:80>
    
      ServerName  physicalhearts.com
      ServerAlias http://www.physicalhearts.com
    
      DocumentRoot public_html/testapp/public
    
      <Location /blog>
        PassengerEnabled off # turn off Passenger for /blog subdirectory
      </Location>
    
    
      RewriteEngine On
      RewriteRule ^/blog/?(.*)$ /public_html/blog.physicalhearts.com/wordpress/$1 [NC,QSA,L]
    
    </VirtualHost>
    

    I think the paths are correct. Thanks for taking a look!

  11. Lee says:

    Ah yeah! Sweet.

    I changed my testapp config to:

    RewriteRule ^/blog/?(.*)$ /etc/apache2/public_html/blog.physicalhearts.com/wordpress/$1 [NC,QSA,L]
    

    But now I am still hitting the rails app when I go to a sub-page on the blog. Any post I try to look at takes me to the index of the Rails app.

    Thanks again for any wisdom you can drop on this problem.


Asset Pipeline has been extracted a...

The asset pipeline which was introduced in Rails 3.1, has ...

ClientSideValidations: Add/Map mode...

#/status/256699237230845952

Action and Page caching has been ex...

With the commit c82cf81f00f Action and Page caching has been extracted ...

turbo-sprockets-rails3: Speeds up ...

#/status/253420357841723393

EdgeRails: ActiveRecord::SessionSto...

With the commit 3324e28804 ActiveRecord::SessionStore is extracted out of Rails into ...

Asset Pipeline has been extracted a...

The asset pipeline which was introduced in Rails 3.1, has ...

ClientSideValidations: Add/Map mode...

#/status/256699237230845952

Action and Page caching has been ex...

With the commit c82cf81f00f Action and Page caching has been extracted ...

turbo-sprockets-rails3: Speeds up ...

#/status/253420357841723393

EdgeRails: ActiveRecord::SessionSto...

With the commit 3324e28804 ActiveRecord::SessionStore is extracted out of Rails into ...