Apache-2.2
如何在 apache2 中部署兩個基於 zend 框架的應用程序,就像在 tomcat 中的應用程序一樣
我有兩個 Zend 框架應用程序,分別稱為
finance
和fleet
. 它們都具有相同的 .htaccess 文件,如下所示RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L]
我創建了兩個名為
fleet.local
和的虛擬主機finance.local
。這是我的fleet.local
文件:# APACHE CONFIGURATION FOR THE fleet.local APPLICATION <VirtualHost *:80> ServerName fleet.local DocumentRoot /home/user/fleet/public SetEnv APPLICATION_ENV dev <Directory /home/user/fleet/public> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> DeflateCompressionLevel 9
這是我的
finance.local
文件:# APACHE CONFIGURATION FOR THE fincance.local APPLICATION <VirtualHost *:80> ServerName fincance.local DocumentRoot /home/user/fincance/public SetEnv APPLICATION_ENV dev <Directory /home/user/fincance/public> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost> DeflateCompressionLevel 9
當我想使用金融時,我會說
http://finance.local
,當我想使用艦隊時,我會說http://fleet.local
。現在我要做的是呼叫一個單獨的虛擬主機
companyX.local
,如果我想要財務應用程序,我只需為我的車隊應用程序鍵入http://companyX.local/finance
和http://companyX.local/fleet
。我該怎麼做呢?
知道了!!!
<VirtualHost *:80> ServerName companyX.local Alias /finance "/home/user/finance/public" <Directory /home/user/finance/public> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> Alias /fleet "/home/user/fleet/public" <Directory /home/user/fleet/public> DirectoryIndex index.php AllowOverride All Order allow,deny Allow from all </Directory> </VirtualHost>
並像這樣更改了財務的重寫基礎:
RewriteEngine On RewriteBase /finance RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L]
並像這樣更改了艦隊的重寫基礎:
RewriteEngine On RewriteBase /fleet RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteRule ^.*$ index.php [NC,L]
試試這個——它甚至不需要 RewriteBase 並且可以在根目錄或子目錄中工作。
RewriteEngine On RewriteCond %{REQUEST_FILENAME} -s [OR] RewriteCond %{REQUEST_FILENAME} -l [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^.*$ - [NC,L] RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$ RewriteRule ^(.*)$ - [E=BASE:%1] RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]