views:

125

answers:

4

We have an existing Zend Framework site hosted at ourdomain.com and a wordpress blog at blog.ourdomain.com

We want to migrate the blog into the site at ourdomain.com/blog - but I seemed to have googled to the end of the earth and cannot find out how. I have tried various .htaccess stuff, setting up a blog controller and including some wordpress files, etc - but to no avail.

Does anyone have any ideas?

virtual host setup:

ServerAdmin [email protected]
DocumentRoot "/Users/bradyeager/Sites/TWPZend/public"
ServerName twps
ErrorLog "logs/twps-error-log"
CustomLog "logs/twps-access_log" common

Options Indexes FollowSymLinks

AllowOverride All

Order allow,deny
Allow from all

A: 

One of the best articles about migrating a non-ZF site into ZF is from Chris Abernethy.

Like you, he sets up a special controller for those non-ZF handled script. However, he (eventually) sets up ZF-routes corresponding to those non-ZF pages, rather than playing around with external .htaccess.

Might not apply directly to your case, since your example involves a subdomain while his involves pages on the same domain. But there are some good ideas in there that might be helpful.

David Weinraub
RewriteEngine OnRewriteCond %{REQUEST_URI} ^/blogRewriteRule ^.*$ - [NC,L]RewriteCond %{REQUEST_FILENAME} !-sRewriteCond %{REQUEST_FILENAME} !-lRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_URI} !^/blogRewriteRule ^.*$ index.php [NC,L]
Brad
A: 

I often use this configuration actually , here's what I do:

 /application
 /library
     /Zend 
     /wordpress ( symlink to my wordpress folder )
 /public
     index.php ( i add wordpress & the zend folder to my include path )

Admittedly a bit of a brutal solution , considering all the unnecessary stuff that's included in the process...

Edit:

// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));

// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'));

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    realpath(APPLICATION_PATH . '/../library/wordpress'),
    get_include_path(),
)));

//Get the wordpress environment
define('WP_USE_THEMES', false);
require_once 'wp-blog-header.php';

/** Zend_Application */
require_once 'Zend/Application.php';  



// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV, 
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap()
            ->run();
PatrickS
Can you post the code on you are including the wordpress folder in the include path? I have the whole "library" folder included
Brad
@Paztrick: Yeah, that is a bit brutal - which is not to say that I haven't done it myself. ;-) Especially if the WP db access is via mysql_xxx() calls and the ZF db access is via something like PDO. Then a single page request can create two distinct db connections, possibly to the same db. See http://stackoverflow.com/questions/2316413/getting-a-php-pdo-connection-from-a-mysql-connect
David Weinraub
OK, so all of this is including just fine, but I still have no idea how this is supposed to work. Are you then adding controllers for your blog? Everything is still routing through the Zend App and its throwing an Invalid Controller (blog) error
Brad
With this solution you would need to add controllers, this is not a redirect of your blog, this is an integration, meaning that you have access to all the Wordpress functions and you can now integrate the content inside your main site by calling the Wordpress functions in your controllers.
PatrickS
A: 

The most efficient and easiest way to accomplish this by modifying your .htaccess file to NOT send anything that starts with /blog to the ZF app -- just pass it through to Wordpress. Wordpress would have to be installed inside your document root, of course, for this to work, exactly how you would normally install it.

An example:

RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]

RewriteRule ^blog - [NC,L]

RewriteRule ^.*$ index.php [NC,L]

All this nonsense about creating custom controllers, actions and routes in your ZF app, then passing off to Wordpress via your app is absolutely ridiculous. You'd be executing a full dispatch cycle of your application's engine, just to forward off to another app?

jason
This is finally where I'm heading, but still to no avail. How is this supposed to work when I have an index.php that has to run the Zend Framework. I'm now going to try install wordpress in public/blog and change the last line to blog/index.php
Brad
Ignore my last comment. I removed the alias completely and put the wordpress install in public/blog and am using your exact .htaccess - but still with a url like http://site/blog/2010/09/23/destination-honeymoon-to-goa-india/ I get invalid controller. Why is the above not ignoring this URI - its still rewriting it to be handled by zend
Brad
I've changed my example to be more forgiving when it comes to where in your directory tree your app is installed. Before it assumed the root of the domain. I've tested this, and it works fine.
jason
I appreciate it, but still no luck. I'm posting my VirtualHost setup in the original post - is there something in the Directory directives that may not be allowing this. It's like its not processing the ^blog or !^blog rules at all. It's serving up the homepage only because /blog/ is a directory : RewriteCond %{REQUEST_FILENAME} -d
Brad
What's the base URL of your app? Is it on the root of your domain? If not, do you have your RewriteBase directive set correctly?
jason
It is the root of my domain. I have no idea - I'm going insane over this. It is definitely reading the rule, because if I inverse it (!^blog) everything else breaks. I have no idea why it is still passing this to the Zend index.php
Brad
In theory I know I shouldn't need to, but do I need a rule matching blog* ?
Brad
Jason - thank you very much. Finally figured it out thanks to you mentioning RewriteBase - it was working correctly, but the .htaccess of my blog folder was rewriting to the /index.php instead of the /blog/index.php (wordpress' controller) So it was actually just looping back into the Zend App. It's miller time!
Brad
Excellent! Glad you got it.
jason
A: 

See the correct answer provided by Jason. Just make sure your wordpress .htacess file is rewriting to the correct index.php By default, it will rewrite back to the base index.php - which belongs to Zend. My solutions was to change Wordpress' .htaccess RewriteBase to /blog instead of /

Brad