2011-07-07 45 views
0

我有幾個小項目,我想在使用Zend Framework的單個虛擬主機上託管。其結構是:在虛擬主機使用Zend Framework託管多個項目的Mod重寫規則

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

文檔根的樣子:DocumentRoot /var/www/apps/

我需要萬能的mod_rewrite規則,這將改變像/apps/testapp1/xxx網址爲/apps/testapp1/index.php

任何幫助將不勝感激,因爲我試圖解決幾個小時。謝謝。

回答

1
  1. 如果你對網站的DocumentRoot爲/var/www/apps/,那麼我想的網址是http://www.example.com/testapp1/ajax而不是http://www.example.com/apps/testapp1/ajax。如果是這樣 - 那麼您需要從這些規則中刪除apps/部分。

  2. 這些規則需要放入您的.htaccess到網站根文件夾中。

  3. 如果您已經有一些規則,那麼這些新規則需要放置在正確的位置規則的順序很重要

  4. 如果您還沒有此類功能,則可能需要在此處添加RewriteEngine On行。

此規則將重寫/apps/testapp1/ajax/apps/testapp1/index.php,沒有其它URL將會受到影響:

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

此規則將重寫與/ajax端插入/index.php(例如/apps/testapp1/ajax =>/apps/testapp1/index.php以及所有URL /apps/testapp2/ajax =>/apps/testapp2/index.php):

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

UPDATE:

這種 「萬能」 的規則將改寫/apps/testapp1/xxx/apps/testapp1/index.php以及/apps/testapp2/something =>/apps/testapp2/index.php

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

感謝您的幫助。你能告訴我一種爲/ testapp1/xxx之類的所有URL創建通用正則表達式的方法嗎?我試過 RewriteRule ^(。+)/(。+)$ /$1/index.php [NC,QSA,L]沒有成功。 –

+0

@Dapper Dan我用「通用」規則更新了我的答案,該規則適用於該類型的URL。 – LazyOne

+0

感謝隊友,您救了我的命! :) –