如何在Heroku上的Rails应用程序中的子URI上运行Wordpress博客

如何在Heroku上的Rails应用程序中的子URI上运行Wordpress博客

问题描述:

I have a rails application that needs a blog. I have looked at various rails cms and blog engines and none of them meet my needs. I would like to add Wordpress on a sub uri www.example.com/blog. My application is hosted on Heroku. I am able to install wordpress independently as a separate app on heroku and I have tried adding wordpress to the public folder with an .htaccess file like this:

RewriteEngine On  
RewriteRule ^([^\.]+[^/])$ http://%{HTTP_HOST}/$1/ [R=301,L]  
RewriteBase /  
RewriteCond RewriteCond %{REQUEST_URI} ^/blog.*$
RewriteCond %{DOCUMENT_ROOT}/-%2 -d  
RewriteRule ^(.*)$ -%2/$1 [QSA,L]  

but to no avail. I cant use reverse proxies because I would like to have SSO (and shared navigation bar etc and really dont want wordpress and my app to be "separate" applications on heroku) between the Rails app and the wordpress installation. Is there a way to achieve this

我有一个需要博客的rails应用程序。 我查看过各种rails cms和博客引擎,但都没有满足我的需求。 我想在子网站www.example.com/blog上添加Wordpress。 我的应用程序托管在Heroku上。 我能够在heroku上独立安装wordpress作为一个单独的应用程序,我尝试使用.htaccess文件将wordpress添加到公共文件夹,如下所示: p>

  RewriteEngine On 
RewriteRule ^  ([^ \。] + [^ /])$ http://%{HTTP_HOST} / $ 1 / [R = 301,L] 
RewriteBase / 
RewriteCond RewriteCond%{REQUEST_URI} ^ / blog。* $ 
RewriteCond%  {DOCUMENT_ROOT} /  - %2 -d 
RewriteRule ^(。*)$  - %2 / $ 1 [QSA,L] 
  code>  pre> 
 
 

但无济于事。 我不能使用反向代理,因为我想在Rails应用程序和wordpress安装之间使用SSO(和共享导航栏等,并且真的不希望wordpress和我的应用程序在heroku上成为“独立”应用程序)。 有没有办法实现这个 p> div>

I would take a look at wordpress-heroku

As far as sub URI's, you start to make things more complex when it's not necessary. If you want you can run two Heroku apps, but instead of using folder paths, use a subdomain so your main app runs on www.example.com and your blog runs on blog.example.com. The use of subdomains is greatly respected in uses like this and makes things a lot easier.

Are you able to access the Virtual Host file for the server? If so then the adding the following in the server may be your answer:

<VirtualHost ...>
  ServerName ...
  DocumentRoot ...
  <Location /blog>
     PassengerEnabled off
     <IfModule mod_rewrite.c>
       RewriteEngine On
       RewriteBase /blog/
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteCond %{REQUEST_FILENAME} !-d
       RewriteRule . /blog/index.php [L]
     </IfModule>
  </Location>
</VirtualHost>

However I guess it also depends on how the rails app is deployed and whether the public folder is updated on deployment. You may need to symlink the public folder so it is not updated each time the site is deployed.

I couldn't say if this would work for Heroku having never used their services but hopefully it will help.

Source: http://ziyedbd.wordpress.com/2012/05/11/deploying-wordpress-blog-inside-ruby-on-rails-application/

Symlink info: http://linux.byexamples.com/archives/19/how-to-create-symlink/