6

我试图让 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

似乎.htaccessSymfony2 ( /another)的app.php_.htaccessindex.phpapp.php

4

2 回答 2

5

似乎RewriteBase需要为 .htaccess 设置配置要求。

RewriteBase /another

这应该有效。此链接有助于此答案。

此外,这里有一些通过我们关于其他设置如何影响以及如何RewriteCond纠正无限内部重定向循环的聊天讨论的注释。可能会帮助其他人。总的来说,mod_rewrite 是一个困难的模块。

于 2013-01-29T20:31:20.163 回答
1

尝试在 sf2 中移动 Symfony 2 别名并为 sf2VirtualHost添加另一个别名: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>
于 2013-01-22T18:55:33.360 回答