11

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 webmaster@dummy-host.example.com
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

Rikesh
  • 26,156
  • 14
  • 79
  • 87
Brad
  • 113
  • 1
  • 1
  • 6
  • What's going wrong? Also, can you post the .htaccess files you're using for both the main site and the WordPress blog? – Tim Stone Sep 26 '10 at 04:43
  • First I have an alias in my httpd.conf: Alias /blog/ "/users/me/blog" And then I just have the standard Zend .htaccess SetEnv APPLICATION_ENV development RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L] But I have no idea why the /blog/ alias won't access any subdirectories. /blog/ works fine - /blog/post/whatever gives a zend "Invalid Controller Blog" – Brad Sep 26 '10 at 06:18
  • Maybe you need to add ZF-routes corresponding to those Wordpress pages? See my answer below. – David Weinraub Sep 26 '10 at 07:25

6 Answers6

15

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
  • 8,918
  • 2
  • 37
  • 43
  • 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 Sep 26 '10 at 17:17
  • 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 Sep 26 '10 at 17:25
  • 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 Sep 26 '10 at 17:32
  • 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 Sep 26 '10 at 17:41
  • 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 Sep 26 '10 at 18:03
  • 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 Sep 26 '10 at 18:10
  • In theory I know I shouldn't need to, but do I need a rule matching blog* ? – Brad Sep 26 '10 at 18:30
  • 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 Sep 26 '10 at 18:33
  • I must say, finally someone who uses rewrites to combine zf and wp. This was very helpful. PS: Have you seen this? http://www.krotscheck.net/2009/05/16/bootstrapping-a-startup-zend-and-wordpress-auth-integration.html – nevvermind Jun 09 '11 at 13:23
  • THANK YOU!! So freaking much. So glad I don't have to make extra virtual hosts now for my other directories... – Benno Jul 20 '11 at 02:28
  • Does this setup allow for pulling in the header and footer from the zend site? I have dynamic elements in the header/footer of my site that I'd like to appear on the wordpress blog. – Adam Youngers Mar 04 '14 at 05:24
1

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
  • 9,539
  • 2
  • 27
  • 31
  • Can you post the code on you are including the wordpress folder in the include path? I have the whole "library" folder included – Brad Sep 26 '10 at 17:45
  • @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 Sep 26 '10 at 18:25
  • 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 Sep 26 '10 at 18:29
  • 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 Sep 27 '10 at 02:26
0

For migrating Wordpress into ZF you can use wploader.
This works for me when i use wordpress as multiple site enabled.
You can use all ZF controller objects inside your wordpress files.
You don't need any hack in your wordpress , so you can upgrade or update your wordpress version easily.

M Rostami
  • 4,035
  • 1
  • 35
  • 39
0

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
  • 14,144
  • 4
  • 42
  • 64
  • RewriteEngine On RewriteCond %{REQUEST_URI} ^/blog RewriteRule ^.*$ - [NC,L] RewriteCond %{REQUEST_FILENAME} !-s RewriteCond %{REQUEST_FILENAME} !-l RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/blog RewriteRule ^.*$ index.php [NC,L] – Brad Sep 26 '10 at 17:13
0

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
  • 113
  • 1
  • 1
  • 6
0

I wrote an open source library that might solve your problem called Vulnero that allows you to run your Zend Framework application inside WordPress. Your routes get handled by your app, everything else goes to WordPress. Can even render your views in your WordPress template if you like. Integrates authentication, database connections, all that. Source is on GitHub or you can read the documentation at http://www.vulnero.com/.

  • While that might be helpful for some other question, it's entirely useless here. This question was about routing requests in `.htaccess`. It was asked and answered over two years ago. Your question adds nothing and seems like little more than an advertisement. – Charles Feb 16 '12 at 08:46
  • 1
    Not really sure how you find it worthless, since routing the requests between his ZF app and his WP install is exactly what I wrote the project for. – Andrew Kandels Mar 25 '12 at 16:42