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/
a开发者_如何学JAVApplication/
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.
If your DocumentRoot for website is
/var/www/apps/
, then I guess URLs would behttp://www.example.com/testapp1/ajax
instead ofhttp://www.example.com/apps/testapp1/ajax
. If so -- then you need to removeapps/
part from these rules.These rules need to be placed in your .htaccess into website root folder.
If you already have some rules there then these new rules needs to be placed in correct place as order of rules matters.
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]
精彩评论