如何在 apache2 中部署两个基于 zend 框架的应用程序,就像在 tomcat 中一样

如何在 apache2 中部署两个基于 zend 框架的应用程序,就像在 tomcat 中一样

我有两个 Zend 框架应用程序,分别称为financefleet。它们都有相同的 .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.localfinance.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/financehttp://companyX.local/fleet输入我的车队应用程序。我该怎么做?

答案1

知道了!!!

<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]

并像这样改变了 fleet 的重写基础:

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]

相关内容