Is it possible to have Rails mask blog.mydomain.com as mydomain.com/blog? - ruby-on-rails

I'd like to install a Wordpress blog that is associated with my domain. I am running a Ruby on Rails app on that domain so I know the easiest thing to do is set up a subdomain for the blog. However, I'd like to keep everything under the same roof, as it were.
How would I go about using Rails/Rack to serve blog.mydomain.com when going to mydomain.com/blog? My first thought was to perform some kind of mask or scrape the other domain and present the HTML as coming from /blog.
The app is running on Heroku, and I'm pretty sure how I would take care of this one an Apache server with .htaccess file (similar to what Wordpress does with permalinks), but I'm not sure how to accomplish this with the tools I have on hand.
Thanks.

You could use rack-rewrite to redirect requests to mydomain.com/blog to blog.mydomain.com.

Related

How can I put a rails app and a wordpress blog on the same domain?

I have a rails 4 app that's hosted on Heroku. Let's say its domain is www.example.com.
I would like to set up a wordpress blog that's hosted elsewhere. I would like the blog to live at www.example.com/blog.
That is, I want to use a subdirectory instead of a subdomain. This is for SEO purposes.
Could you please provide advice on how I can implement this?
UPDATE: This is a new site, and the blog isn't set up yet. So there are not any incoming links to worry about breaking.
UPDATE #2: I tried using rack-reverse-proxy on heroku. The /blog/ pages were rendering fine. However, I would actually get redirected to blog.example.com/blog/ instead of keeping the displayed url www.example.com/blog/. I used the same code in the rack-reverse-proxy README. However, I can't find any evidence of anyone having done this successfully with rails 4. I moved the server from heroku to EC2 and now I'm going to try some more stuff.
301 redirect requests for /blog to blog.example.com and setup a DNS entry for the blog subdomain.
Web bots/crawlers will update their indexes with a 301
You could also try something like https://github.com/jaswope/rack-reverse-proxy but judging by the nature of the question itself, that might be out of the scope of knowledge

Rails - how to redirect from www.website.com to website.com

I would like to redirect all requests, that coming to www.website.com/whatever to the variant without www.
How to do this in Rails & what is the best way to do that?
There are two options for this. If you want to do it within rails the following gem might be useful
https://github.com/iSabanin/www_ditcher
However, such tasks are generally configured from the app server. Please look at this question previously posted on stack overflow
301 redirect in Passenger (Ruby on Rails) from root domain to www sub domain?
It does the complement of what you seek to do, however it should get you on track. Thanks!
I think it's best to keep the logic for that completely our of your Rails app and rather take care of it in the server configuration.
gem 'rack-www' works nicely for this.
https://github.com/stjhimy/rack-www

Need to link WP Blog with Rails App on Heroku

I have a client who wants to migrate his Rails app to Heroku. However the client also has a blog associated with his domain that runs on WordPress. Currently, the WordPress blog is running happily alongside the Rails app, but once we migrate to Heroku, that clearly won't be possible.
The url for the app is like http://mydomain.com, and the url for the blog is like http://mydomain/blog.
I realize that the best long-term solution is to redo the blog in a Rails format like Toto or Jekyll. But in the short term, what is the best way to continue hosting the WP blog where it is (or somewhere) but use Heroku to run the app? The client doesn't want the blog to be on a subdomain, but to remain at mydomain/blog for SEO reasons and also since there is traffic to the blog. I have two ideas:
Use rack_rewrite or refraction (or just a regular old 301 and Apache mod_rewrite) on the old (non-Heroku) server to redirect the main url from the old site to Heroku. In this case, I can just leave the Wordpress blog running happily where it is. I think?? Is there a reason to choose one of those options (rack_rewrite, refraction, or mod_rewrite) over the others if I do it this way?
Switch the DNS info to point to the Heroku site, and then use a 301 redirect from the blog to the old site. But then I'll have to get the old (non-Heroku) site on a subdomain and use some kind of rewrite rules anyway so it looks like it isn't a subdomain.
Are either of these approaches preferable, or is there another way to do it that's easier that I'm missing?
The only tenable long term/scalable solution would be to host the blog permanently on a sub-domain or different domain and add a redirect from mydomain.com/blog to the new location (ie: blog.mydomain.com).
You would need a single server running a front-end like Apache/nginx on mydomain.com to serve up mixed back-ends like Rails and Wordpress and that is not possible on Heroku.
Sadly, this is where you need to dig in as a consultant and be stern with your client about the technical limitations.
Why does you client want to migrate to Heroku? Is there a larger goal behind that you could accomplish with different hosting where you control the front-end and can mix in different back ends?
Another solution is to set heroku to http://app.example.com, and Wordpress to http://example.com. You put your Wordpress-landing page in the root , and blog on /blog. When the user click "login" or "signup" on the landing-page, they're linked to the heroku-app.
This will be optimal in a SEO-perspective, but require some DNS-knowledge.
Winfield's answer is not correct. You can run a reverse proxy on your rack server (via Heroku) to direct to the blog, wherever it may be.
See https://github.com/jaswope/rack-reverse-proxy
After you install the gem and set up your app according to the docs, your ./config.ru file will have something like this:
use Rack::ReverseProxy do
reverse_proxy(/^\/blog(\/.*)$/,
'http://<app-name>.herokuapp.com$1',
opts = {:preserve_host => true})
end

How do I serve multiple rails apps on one domain (and sub)?

This is kind of weird but I'd like to serve multiple websites on the same domain. If possible, we want to avoid subdomains to keep urls simple for our users - no need for them to know it's two separate apps. This is purely for keeping the code bases separate. Any ideas?
For example:
Rails App 1 (Refinery CMS) serves:
http://example.com/
http://example.com/about
http://example.com/pricing
Rails App 2 (our real App) serves:
http://example.com/account
http://example.com/store
http://example.com/listings
We use ruby 1.9.2, ruby on rails, refinery cms, apache and passenger.
If you're using Passenger, check out the Deploying to a sub URI portion of the manual - it's quite simple to set up an app on a sub-URI. You may need to set config.action_controller.relative_url_root in your app configuration, as well.
Edit: I misread the question; not one app per URI, but one app serving some (but not all) endpoints. This is actually moderately easy to do with some basic rewrites, as well.
Deploy your Rails app to, let's say, /railsapp (but without setting relative_url_root). Now, in .htaccess:
RewriteRule ^account/(.*)$ railsapp/account/$1 [L]
This will internally remap /account/* to /railsapp/account/*, so as long as you set up a rewrite per path your Rails app handles, it should work fine.
Subdomains make it easier (thus why most sites have shop.example.com), but you could probably use rewrite rules with name based virtual host routing. How exactly to do that I'm not sure. More of a Apache rewrite question for SuperUser.
A word of warning if you are using SSL you might have issues arise.
You could set it up to first hit one app where you expect most URLs would work and if it 404s you could instruct it to try the other app next, though this will be slower than routing per route but it will work without having to hardcode a route for every page that is created on say, Refinery CMS.
Currently I'm also working on a same kind of CMS. In my case also I need multiple sub domains, like
www.test1.mydomain.com
www.test2.mydomain.com
www.test3.mydomain.com
www.test4.mydomain.com
here is what I did
in rails 3 (if you are on rails3) you can get the sub domain by using request object. (If you are on rails 2.x you can use sub domain_fu plugin)
In my case I have used a before filter to get the sub domain, after that I load the site according to the sub domain
For development use the following public domain "lvh.me"
http://tbaggery.com/2010/03/04/smack-a-ho-st.html
this was very useful for me http://railscasts.com/episodes/221-subdomains-in-rails-3
let users have their domains forwarded to your subdomain (with masking)
ex : www.clientdomain.com --> http://client.mydomain.com
hope this helps
cheers
sameera

Is it possible to use modify nginx config file and use X-Accel-Redirect on Heroku?

Reading this article on nginx website, I'm interested in using X-Accel-Redirect header in the way that Apache or Lighttpd users might use the X-Sendfile header to help with the serving of large files.
Most tutorials I've found require you to modify the nginx config file.
Can I modify the nginx config file on Heroku and if so, how?
Secondly,
I found this X-Accel-Redirect plugin on github which looks like it removes the need to manually alter the nginx config file - it seems to let you add the redirect location in your controller code - does anyone know if this works on heroku? I can't test it out until tonight.
NB - I have emailed both Heroku support and goncalossilva to ask them the same questions but I have no idea when they will get back to me. I will post back with whatever it is they tell me though.
Although Heroku seem to be using Nginx for their reverse-proxy component, the thing about a platform-as-a-service stack like this is that no individual tenant has to (nor even gets to) configure or tune distinct elements of the stack for any given application.
Requests in and out could be routed through any number of different elements to and from your Rails app so it's their platform infrastructure (and not any particular tenant) that manages all of the internal configuration and behavior. You give up the fine-grained control for the other conveniences offered by a PaaS such as this.
If you really need what you've described then I'd suggest you might need to look elsewhere for Rails app hosting. I'd be surprised if their answer would be anything else but no.

Resources