Published in WordPress
avatar
4 minutes read

How can I use a subdirectory instead of a subdomain?

I'm constructing a rails application that I'll have on Heroku at domain.com. Furthermore, I might want to involve WordPress for the blog facilitated on phpfog, yet I would rather not utilize a subdomain like blog.domain.com. I'd rather really like to utilize a subdirectory like domain.com/blog

It's really not necessary to focus on SEO...I'm simply not an enthusiast of subdomains. Subdirectories are hotter (yeah...I really said that).

Any thought on how I can dependably achieve this? Much obliged ahead of time for the assistance.

Solutions

You can utilize the rack-invert intermediary jewel that neezer tracked down to do this. First you'll need to add diamond "rack-turn around intermediary", :require => "rack/reverse_proxy" to your Gemfile and run group introduce. Then, you'll change your config.ru to advance the/blog/course to your ideal 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 most likely as of now have the first require proclamation and the run YourAppName... proclamation. There are a couple significant subtleties that make this work.

To start with, when you add your ideal blog URL, you can't keep the following cut on it. On the off chance that you do, when somebody demands http://yourdomain.com/blog/, the jewel will advance them to http://you.yourbloghost.com//with an additional following slice.

Besides, if the :preserve_host choice isn't empowered, your blog facilitating server will view the solicitation as being for http://yourdomain.com/blog/rather than as http://you.yourbloghost.com and will return awful outcomes.

You actually may dislike the CSS or pictures assuming the blog utilizes/outright/ways/to/pictures/.

Comments