Alias โ€‹โ€‹and mod_rewrite

I am trying to get Symfony1.4 and Symfony2 to work on the same host in Apache (2.2.22). I think the problem is that both use mod_rewrite to direct the request to the php controller / script. Here is my configuration

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> 

And then each version of Symfony has .htaccess , which is used to re-record the request

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> 

I want to use localhost/ to redirect to the front Symfony 1 controller index.php , but when I use localhost/another , all requests should be redirected to the front Symfony2 app.php controller, but they are not - they are redirected to the front symfony1 controller ( index.php ). If I use the controller file name for Symfony2, it works, i.e. localhost/another/app.php

How can I get apache to forward requests to a Symfony2 controller when I use the /another alias?

Update

I turned on rewrite logging ... this is what I got:

 [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 

It seems that .htaccess for Symfony2 ( /another ) is read and redirected to app.php , but then it reads another .htaccess and then redirected to index.php ... How can I get rewrite to stop on app.php

+6
source share
2 answers

It seems that configuration requires a RewriteBase for .htaccess.

 RewriteBase /another 

That should work. This link helped in this answer.

Also, here are some notes in our chat discussion about how other settings can affect and how RewriteCond can fix endless loop internal redirection. May help other people. In general, mod_rewrite is one complex module.

+5
source

Try moving the Symfony 2 alias inside VirtualHost and adding another DirectoryIndex for sf2:

 <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> 
+1
source

All Articles