我在Heroku上有Rails應用程序,在GoDaddy上有一個單獨的WordPress博客。如何將RailsApp.com/blog路由到WordPress,同時將其作爲應用程序的子目錄進行維護?使現有的WordPress博客成爲Rails應用程序的子目錄?
3
A
回答
3
對於Rails3.1 +(+ Rails4),你應該按照下面這些: 首先,將gem rack-proxy添加到Gemfile中
寶石 「機架代理」
然後添加文件proxy.rb到Rails.root/lib目錄是這樣的:
require 'rack/proxy'
class Proxy < Rack::Proxy
def initialize(app)
@app = app
end
def call(env)
original_host = env["HTTP_HOST"]
rewrite_env(env)
if env["HTTP_HOST"] != original_host
perform_request(env)
else
# just regular
@app.call(env)
end
end
def rewrite_env(env)
request = Rack::Request.new(env)
if request.path =~ /^\/blog(\/.*)$/
# enable these code if you set blog as ROOT directory in wordpress folder
# env['REQUEST_PATH'] = '/'
# env['ORIGINAL_FULLPATH'] = '/'
# env['PATH_INFO'] = '/' # set root path request
env['REQUEST_URI'] = 'http://tinle1201.wordpressdomain.com' # your path
env["SERVER_PORT"] = 80
env["HTTP_HOST"] = "tinle1201.wordpressdomain.com" # point to your host
end
env
end
end*
註冊代理中間件到的config/application.rb中:
require File.expand_path('../boot', __FILE__)
require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(:default, Rails.env)
module AdultSavings
class Application < Rails::Application
config.autoload_paths += %W(#{config.root}/lib)
config.middleware.use "Proxy"
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
# config.time_zone = 'Central Time (US & Canada)'
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
# config.i18n.default_locale = :de
end
end*
添加兩行到PHP文件的wp-config.php文件:enter code here
define('WP_SITEURL', 'http://tinle1201.wordpressdomain.com/blog');
define('WP_HOME', 'http://tinle1201.wordpressdomain.com/blog');
0
Rails的配置
加入Gemfile中:
gem "rack-reverse-proxy", :require => "rack/reverse_proxy"
現在,我們希望/博客和/博客/被定向到從Rails應用程序WordPress的實例。
添加到您的config.ru你運行應用程序權利之前:
use Rack::ReverseProxy do
reverse_proxy(/^\/blog(\/.*)$/,
'http://CHANGEME.herokuapp.com$1',
opts = {:preserve_host => true})
end
在配置/ routes.rb中添加一條路由:
match "/blog" => redirect("/blog/")
更多信息here
相關問題
- 1. WordPress的博客Android應用程序
- 2. Heroku的Wordpress博客應用程序
- 3. 將新博客添加到現有Rails4.0應用程序/ blog子目錄
- 4. 將博客功能添加到現有的Rails應用程序
- 5. 如何將WordPress博客與我的Grails應用程序集成?
- 6. 子目錄中的Rails應用程序
- 7. 在Rails應用程序中添加wordpress博客
- 8. WordPress的博客帖子出現在facebook
- 9. 爲自己託管的博客重塑Wordpress Android應用程序
- 10. 在根目錄中存在.htaccess文件在子目錄中使用WordPress博客
- 11. Ghost博客與應用程序集成
- 12. 在Rails應用程序的子域中的WordPress博客 - 下載文件並且不呈現它們
- 13. 從godaddy運行的子目錄上的WordPress博客
- 14. WordPress的拉博客帖子
- 15. Octopress博客作爲rails子目錄,與github公共存儲庫
- 16. 博客WordPress的博客
- 17. Ruby on Rails博客應用程序帖子顯示
- 18. WordPress的 - 從根移動博客就是子目錄
- 19. wordpress博客在magento根文件夾的子目錄中
- 20. 使用vb.net應用程序在wordpress博客上發帖
- 21. 如何爲Wordpress博客製作應用程序?
- 22. Django博客應用程序
- 23. 供應wordpress用戶/博客
- 24. 我無法使用「rails新博客」創建新應用程序
- 25. 如何在博客中爲rails應用程序構建評論?
- 26. WordPress博客用最少的集成
- 27. 整合WordPress的博客,以iPhone應用程序
- 28. 主持一個與django應用程序並行的WordPress博客
- 29. WordPress的博客iPhone應用程序讀取器
- 30. 與java應用程序集成的博客引擎。哪個博客引擎?
我非常瞭解那篇文章,儘管它適用於基於heroku的wordpress。這是我嘗試解決方案的一部分,我可以讓博客顯示在正確的子目錄中,但是當您單擊博客上的任何內容時,它會切換到博客的域。 – DogNibbler
爲了解決此問題,我將wordpress上的網站地址URL更改爲mywebsite.com/blog,並將rewritebase/blog /添加到.htaccess。這適用於開箱即用的wordpress,因爲帖子是用/?p = 1這樣的擴展來組織的,因爲這會轉到第一篇文章。我正在嘗試使用的大量修改的博客有像blogurl.com/name-of-article那樣組織的帖子,並且由於某些原因,當我嘗試使用相同的確切解決方案單擊主頁上的帖子時,會將我帶到我的根目錄站點而不是訪問文章 – DogNibbler
請注意,「機架反向代理」不適用於生產系統。最好使用您的網絡服務器(如Nginx或Apache)來配置生產中的代理傳遞設置。 –