Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I'm building a rails app that I'll host on Heroku at domain.com. And I'd like to use WordPress for the blog hosted on phpfog, but I don't want to use a subdomain like blog.domain.com. I'd instead prefer to use a subdirectory like domain.com/blog

Its not about SEO...I'm just not a fan of subdomains. Subdirectories are sexier (yeah...I actually said that).

Any idea on how I can reliably accomplish this? Thanks in advance for the help.

share|improve this question
    
I don't know if it's possible, because you can't host Wordpress under Heroku. – bruno077 May 30 '11 at 18:08
    
Based on the answers below, along with the bit of research I did, I'm thinking it might better to just roll my own little rails blog engine into my app. I've seen the "build a blog in 15 minutes" rails videos. I don't want to use the scaffolding (I could probably do it without any). My app is kinda blog-esque to begin with anyhow...posts, comments, etc. I'll have to set some kind of user-permissions so that only those with admin accounts can post to the blog though. – Eddie May 30 '11 at 22:33
    
I can't recommend Ryan's railscasts enough for this project, he has examples with a blog so there are a lot of resources which can help you. railscasts.com – bruno077 May 30 '11 at 22:58
1  
Thanks Bruno...I'll check those out. Currently reading Ruby on Rails 3 Tutorial by Michael Hartl. – Eddie May 31 '11 at 0:37
    
FYI there is a Rails blog which is about a quarter as powerful as Wordpress called Refinery CMS ruby-toolbox.com/projects/refinerycms. It's not WordPress but it's a native solution. – Chloe Sep 3 '15 at 2:01

You can use the rack-reverse-proxy gem that neezer found to do this. First you'll want to add gem "rack-reverse-proxy", :require => "rack/reverse_proxy" to your Gemfile and run bundle install. Next, you'll modify your config.ru to forward the /blog/ route to your desired blog:

require ::File.expand_path('../config/environment',  __FILE__)

use Rack::ReverseProxy do  
       reverse_proxy /^\/blog(\/.*)$/, 'http://notch.tumblr.com$1', opts={:preserve_host => true}
end

run YourAppName::Application

You probably already have the first require statement and the run YourAppName... statement. There are a couple important details that make this work.

First, when you add your desired blog URL, you can't keep the trailing slash on it. If you do, when someone requests http://yourdomain.com/blog/, the gem will forward them to http://you.yourbloghost.com// with an extra trailing slash.

Secondly, if the :preserve_host option isn't enabled, your blog hosting server will see the request as being for http://yourdomain.com/blog/ instead of as http://you.yourbloghost.com and will return bad results.

You still may have an issue with the CSS or images if the blog uses /absolute/paths/to/images/.

share|improve this answer
    
How do you handle the fact that tumblr uses absolute URLs to link to content which include the host name? – Chris Nicola Oct 8 '12 at 21:43
    
Chris, I'm afraid that I don't have a great solution for that. I was using Wordpress where you can manually specify the base path it'll use in page content, so I didn't need to address that. If you want to wade into customizing the source code for rack-reverse-proxy, you could modify it so that it edits the HTML that Tumblr returns.. – jplewicke Oct 14 '12 at 14:32
    
Yeah I was playing around trying to figure out how to do that. I was thinking of doing some regex replacing, but it wasn't clear from the docs exactly how that would be done. – Chris Nicola Oct 17 '12 at 3:38
1  
If you want to catch /blog (w/o trailing slash) reverse_proxy /^\/blog(\/?.*)$/, 'notch.tumblr.com$1';, opts={:preserve_host => true} – micred Mar 4 '13 at 13:12
    
this works well - how do you alter the wordpress settings so the CSS still works? – Ryan Perera Jun 27 '13 at 22:56

I'd say your best bet is to try and do a reverse proxy with Rack middleware (akin to Apache's mod_proxy).

A quick Google search revealed this gem ( https://github.com/jaswope/rack-reverse-proxy ), but the author mentions that it's probably not production-ready. Having a Rack middleware proxy should allow you to forward your subdomain yourdomain.com/blog to another website your-phpfog-account.com/wordpress-installation.

share|improve this answer

As far as I can tell you can't access the Apache config file with heroku if you could you could use a Rewrite rule.

If you choose not to use heroku you can always do what I detail below.. However if you're not using heroku you could just as easily extract wordpress to the /public/ rails folder and once again use a rewrite rule to get apache to handle the blog requests.

In your apache configuration you'll need to add.

RewriteRule ^/blog/?(.*)$ http://somedomain.com/~user/blog/$1 [P,NC,QSA,L]

It will redirect all requests to /blog/ to the other server.

Source: http://www.igvita.com/2007/07/04/integrating-wordpress-and-rails/

share|improve this answer
    
I don't think a rewrite is what he wants, since that will change the address in the URL bar to another-domain.com/blog instead of original-domain.com/blog. – neezer May 30 '11 at 21:03
    
Ah I see. I'm not familiar with how mod_rewrite works. I just did some googling and assumed that would do what he wanted. – Jamie Maddocks May 30 '11 at 21:18

In addition to jplewickeless' answer, I ended up writing custom Rack middelware to replace absolute urls and other paths at the side of the reverse proxy. This guide will get you started on that:

http://railscasts.com/episodes/151-rack-middleware

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.