我试图让 Symfony1.4 和 Symfony2 在 Apache(2.2.22)中的同一主机上工作 - 我认为问题在于两者都使用 mod_rewrite 将请求定向到 php 控制器/脚本。这是我的配置
httpd.conf
# Symfony 1.4
<VirtualHost *:80>
DocumentRoot "d:/wamp/www/wlnew/web"
DirectoryIndex index.php
<Directory "d:/wamp/www/wlnew/web">
AllowOverride All
Allow from All
</Directory>
Alias /sf d:/wamp/www/wlnew/lib/vendor/symfony/data/web/sf
<Directory "d:/wamp/www/wlnew/lib/vendor/symfony/data/web/sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
# Symfony 2
Alias /another "d:/wamp/www/another/web/"
<Directory "d:/wamp/www/another/web">
Options Indexes FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
然后每个版本的 Symfony 都有一个.htaccess
用来重写请求的
Symfony 1.htaccess
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
Symfony 2.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
我希望能够使用localhost/
重定向到 Symfony 1 前端控制器index.php
,但是当我使用时,localhost/another
所有请求都应该转发到 symfony2 前端控制器app.php
,但它们不是——它们被转发到 symfony1 前端控制器(index.php
)。如果我为 Symfony2 使用控制器的文件名,它可以工作,即localhost/another/app.php
/another
当我使用别名时,如何让 apache 将请求转发到 Symfony2 控制器?
更新
我启用了重写日志记录......这就是我得到的:
[perdir D:/wamp/www/another/web/] strip per-dir prefix: D:/wamp/www/another/web/ ->
[perdir D:/wamp/www/another/web/] applying pattern '^(.*)$' to uri ''
[perdir D:/wamp/www/another/web/] RewriteCond: input='D:/wamp/www/another/web/' pattern='!-f' => matched
[perdir D:/wamp/www/another/web/] rewrite '' -> 'app.php'
[perdir D:/wamp/www/another/web/] add per-dir prefix: app.php -> D:/wamp/www/another/web/app.php
[perdir D:/wamp/www/another/web/] internal redirect with D:/wamp/www/another/web/app.php [INTERNAL REDIRECT]
[perdir D:/wamp/www/wlnew/web/] add path info postfix: D:/wamp/www/wlnew/web/wamp -> D:/wamp/www/wlnew/web/wamp/www/another/web/app.php
[perdir D:/wamp/www/wlnew/web/] strip per-dir prefix: D:/wamp/www/wlnew/web/wamp/www/another/web/app.php -> wamp/www/another/web/app.php
[perdir D:/wamp/www/wlnew/web/] applying pattern '^$' to uri 'wamp/www/another/web/app.php'
[perdir D:/wamp/www/wlnew/web/] add path info postfix: D:/wamp/www/wlnew/web/wamp -> D:/wamp/www/wlnew/web/wamp/www/another/web/app.php
[perdir D:/wamp/www/wlnew/web/] strip per-dir prefix: D:/wamp/www/wlnew/web/wamp/www/another/web/app.php -> wamp/www/another/web/app.php
[perdir D:/wamp/www/wlnew/web/] applying pattern '^([^.]+)$' to uri 'wamp/www/another/web/app.php'
[perdir D:/wamp/www/wlnew/web/] add path info postfix: D:/wamp/www/wlnew/web/wamp -> D:/wamp/www/wlnew/web/wamp/www/another/web/app.php
[perdir D:/wamp/www/wlnew/web/] strip per-dir prefix: D:/wamp/www/wlnew/web/wamp/www/another/web/app.php -> wamp/www/another/web/app.php
[perdir D:/wamp/www/wlnew/web/] applying pattern '^(.*)$' to uri 'wamp/www/another/web/app.php'
[perdir D:/wamp/www/wlnew/web/] RewriteCond: input='D:/wamp/www/wlnew/web/wamp' pattern='!-f' => matched
[perdir D:/wamp/www/wlnew/web/] rewrite 'wamp/www/another/web/app.php' -> 'index.php'
[perdir D:/wamp/www/wlnew/web/] add per-dir prefix: index.php -> D:/wamp/www/wlnew/web/index.php
[perdir D:/wamp/www/wlnew/web/] strip document_root prefix: D:/wamp/www/wlnew/web/index.php -> /index.php
[perdir D:/wamp/www/wlnew/web/] internal redirect with /index.php [INTERNAL REDIRECT]
[perdir D:/wamp/www/wlnew/web/] strip per-dir prefix: D:/wamp/www/wlnew/web/index.php -> index.php
[perdir D:/wamp/www/wlnew/web/] applying pattern '^$' to uri 'index.php'
[perdir D:/wamp/www/wlnew/web/] strip per-dir prefix: D:/wamp/www/wlnew/web/index.php -> index.php
[perdir D:/wamp/www/wlnew/web/] applying pattern '^([^.]+)$' to uri 'index.php'
[perdir D:/wamp/www/wlnew/web/] strip per-dir prefix: D:/wamp/www/wlnew/web/index.php -> index.php
[perdir D:/wamp/www/wlnew/web/] applying pattern '^(.*)$' to uri 'index.php'
[perdir D:/wamp/www/wlnew/web/] RewriteCond: input='D:/wamp/www/wlnew/web/index.php' pattern='!-f' => not-matched
[perdir D:/wamp/www/wlnew/web/] pass through D:/wamp/www/wlnew/web/index.php
似乎.htaccess
Symfony2 ( /another
)的app.php
_.htaccess
index.php
app.php