Dapper Dan
Dapper Dan

Reputation: 3

Mod rewrite rules for hosting multiple projects using Zend Framework

I have several small projects I want to host on single virtual host using Zend Framework. The structure is:

    apps/
        testapp1/
          application/
          index.php,
        testapp2/
          application/
          index.php

Document root in virtual host looks like: DocumentRoot /var/www/apps/

I need univeral mod_rewrite rule which will transform URLs like /apps/testapp1/xxx into /apps/testapp1/index.php.

Any help will be greatly appreciated as I am trying to resolve that for several hours. Thank You.

Upvotes: 0

Views: 500

Answers (1)

LazyOne
LazyOne

Reputation: 165278

  1. If your DocumentRoot for website is /var/www/apps/, then I guess URLs would be http://www.example.com/testapp1/ajax instead of http://www.example.com/apps/testapp1/ajax. If so -- then you need to remove apps/ part from these rules.

  2. These rules need to be placed in your .htaccess into website root folder.

  3. If you already have some rules there then these new rules needs to be placed in correct place as order of rules matters.

  4. You may need to add RewriteEngine On line there if you do not have such yet.

This rule will rewrite /apps/testapp1/ajax into /apps/testapp1/index.php, no other URLs will be affected:

RewriteRule ^apps/testapp1/ajax$ /apps/testapp1/index.php [NC,QSA,L]

This rule will rewrite ALL URLs that end with /ajax into /index.php (e.g. /apps/testapp1/ajax => /apps/testapp1/index.php as well as /apps/testapp2/ajax => /apps/testapp2/index.php):

RewriteRule ^(.+)/ajax$ /$1/index.php [NC,QSA,L]

UPDATE:

This "universal" rule will rewrite /apps/testapp1/xxx into /apps/testapp1/index.php as well as /apps/testapp2/something => /apps/testapp2/index.php:

RewriteRule ^(.+)/([^/\.]+)$ /$1/index.php [NC,QSA,L]

Upvotes: 1

Related Questions