我正在尝试让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前端控制器{{1}但它们不是 - 它们被转发到symfony1前端控制器(app.php
)。如果我为Symfony2使用控制器的文件名,它就可以工作,即index.php
当我使用localhost/another/app.php
别名时,如何让apache将请求转发到Symfony2控制器?
我启用了重写日志记录的记录......这就是我得到的:
/another
似乎正在读取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
)并重定向到/another
,但随后读取另一个app.php
,然后重定向到{{1我怎样才能让重写停在.htaccess
答案 0 :(得分:5)
似乎需要为.htaccess设置RewriteBase
配置。
RewriteBase /another
这应该有效。 This link helped in this answer.
另外,here are some notes through our discussion on chat了解其他设置如何影响以及RewriteCond
如何纠正无限内部重定向循环。可能会帮助其他人。总的来说,mod_rewrite是一个困难的模块。
答案 1 :(得分:1)
尝试在VirtualHost
内移动Symfony 2别名,并为sf2添加另一个DirectoryIndex
:
<VirtualHost *:80>
# Symfony 1.4
DocumentRoot "d:/wamp/www/wlnew/web"
<Directory "d:/wamp/www/wlnew/web">
DirectoryIndex index.php
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>
# Symfony 2
Alias /another "d:/wamp/www/another/web/"
<Directory "d:/wamp/www/another/web">
DirectoryIndex app.php
Options Indexes FollowSymlinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>