简体   繁体   中英

How to run Wordpress Blog on a Sub URI within a Rails App on Heroku

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

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM