Need to link WP Blog with Rails App on Heroku

ⅰ亾dé卋堺 提交于 2019-12-10 10:15:03

问题


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:

  1. 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?

  2. 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?


回答1:


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?




回答2:


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.




回答3:


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


来源:https://stackoverflow.com/questions/5130795/need-to-link-wp-blog-with-rails-app-on-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!