Its all about Ruby On Rails
Hosting Rails app and WordPress on same domain(as folder instead of subdomain)
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.
| Print article | This entry was posted by Akhil Bansal on August 8, 2008 at 2:05 pm, and is filed under Rails, SEO, apache, hosting, wordpress. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |

about 2 years ago
Thanks for the post brother.
~Amit
about 1 year ago
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?
about 1 year ago
Woh!! it helped me again while setting up rails and wordpress. Good, I wrote a blogpost earlier.
about 11 months ago
Hi! I was surfing and found your blog post… nice! I love your blog.
Cheers! Sandra. R.
about 10 months ago
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)
about 2 months ago
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.