Fixing a rewrite issue in WordPress and Zend Framework

While working on an application for a client, I was faced with below rewrite issue.
The client was using WordPress as the CMS and wanted a restful API service which i had to develop for them.

The requirement was to develop Rest API using Zend Framework.
Once I have written the Rest API, I had some conflicting issues with rewrite rules.

The WordPress application was installed at the web root directory whereas the API service was on a sub-folder /api

So a rest uri with http://www.domain.co.nz/api/account/1234 was giving a 404 WordPress error. I had a look at WordPress .htaccess file but it contained tonnes of rules for W3 Total Cache plugin for WordPress.

I did not want to even touch WordPress .htaccess file so i tried to modify only /api/.htaccess file.
After a bit of tweaking i managed to get the api working. Below are the rewrite rules.


SetEnv APPLICATION_ENV production
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ api/index.php [NC,L]

Hope this helps someone working on Zend and WordPress on same server root.

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image