我目前有一個Rails應用程序my_app.com
和一個關聯的Wordpress博客blog.my_app.com
。他們都在Heroku上獨立運行(即沒有Apache或Nginx腳本)將Wordpress博客路由到Rails子文件夾 - 博客鏈接未更改
我想將博客移動到Rails應用程序的子文件夾my_app.com/blog
而不會丟失任何博客現有的搜索引擎優化「果汁」。
我已經實現了rack-reverse-proxy gem,並且博客的主頁按照要求忠實地出現在http://my_app.com/blog/
處。但是,博客中嵌入的所有鏈接仍指向子域,而不是應用程序的博客文件夾。
如何配置博客鏈接到http://my_app.com/blog/post1
而不是blog.my_app.com/post1
?
我config.ru文件:
require ::File.expand_path('../config/environment', __FILE__)
use Rack::ReverseProxy do
reverse_proxy(/^\/blog(\/.*)$/, 'http://my-blog.herokuapp.com$1', opts = {:preserve_host => true})
end
use Rack::Deflater
run MyBlog::Application
在我的routes.rb:
constraints domain: 'blog.my_app.com' do
get '(*path)' => 'application#blog'
end
get "/blog" => redirect("/blog/")
在我的ApplicationController:
def blog
redirect_to "http://my_app.com{request.fullpath.gsub('/blog','')}", :status => :moved_permanently
end
我WP .htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>