LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (http://www.linuxquestions.org/questions/linux-server-73/)
-   -   Apache2 mod vhost_alias - problems with .htaccess mod rewrite (http://www.linuxquestions.org/questions/linux-server-73/apache2-mod-vhost_alias-problems-with-htaccess-mod-rewrite-577636/)

d_t_baker 08-16-2007 05:02 PM

Apache2 mod vhost_alias - problems with .htaccess mod rewrite
 
Hello all!

For those not familiar with mod vhost_alias it allows you to configure dynamic virtual hosts within apache.
For example loading http://test.localdev/ reads from the dynamic site /var/www/test , and loading http://FOOBAR.localdev/ will read from /var/www/FOOBAR

Heres is the configuration:
Code:

<VirtualHost *>
        ServerName localdev
        ServerAlias *.localdev

        VirtualDocumentRoot /var/www/%-2+/

        <Directory /var/www>
                Options Indexes FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/%-2+>
                Options Indexes FollowSymLinks
                AllowOverride All
        </Directory>

        ErrorLog /var/log/apache2/error.log

        CustomLog /var/log/apache2/access.log combined
        ServerSignature On

</VirtualHost>

This works great and I can access any virtual site that has a directory entry in /var/www/.
However as soon as I throw a .htaccess with modrewrite into one of my dynamic virtual hosts I get some funky errors.

example .htaccess file in /var/www/test/:
Code:

RewriteEngine On
RewriteRule ^(.*)$ index.php

now when i load http://test.localdev/ I get 500 internal server error:
[HTML]<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
dtbaker@gmail.com and inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.2.3 (Debian) PHP/5.2.0-10 Server at test.localdev Port 80</address>[/HTML]

this is what I get in the error.log:

Code:

[Fri Aug 17 08:13:22 2007] [error] [client 192.168.5.80] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
[Fri Aug 17 08:13:22 2007] [debug] core.c(3027): [client 192.168.5.80] r->uri = /var/www/test/index.php
[Fri Aug 17 08:13:22 2007] [debug] core.c(3033): [client 192.168.5.80] redirected from r->uri = /var/www/test/index.php
[Fri Aug 17 08:13:22 2007] [debug] core.c(3033): [client 192.168.5.80] redirected from r->uri = /var/www/test/index.php
[Fri Aug 17 08:13:22 2007] [debug] core.c(3033): [client 192.168.5.80] redirected from r->uri = /var/www/test/index.php
[Fri Aug 17 08:13:22 2007] [debug] core.c(3033): [client 192.168.5.80] redirected from r->uri = /var/www/test/index.php
[Fri Aug 17 08:13:22 2007] [debug] core.c(3033): [client 192.168.5.80] redirected from r->uri = /var/www/test/index.php
[Fri Aug 17 08:13:22 2007] [debug] core.c(3033): [client 192.168.5.80] redirected from r->uri = /var/www/test/index.php
[Fri Aug 17 08:13:22 2007] [debug] core.c(3033): [client 192.168.5.80] redirected from r->uri = /var/www/test/index.php
[Fri Aug 17 08:13:22 2007] [debug] core.c(3033): [client 192.168.5.80] redirected from r->uri = /var/www/test/index.php
[Fri Aug 17 08:13:22 2007] [debug] core.c(3033): [client 192.168.5.80] redirected from r->uri = /var/www/test/index.php
[Fri Aug 17 08:13:22 2007] [debug] core.c(3033): [client 192.168.5.80] redirected from r->uri = /

I have increased 'LimitInternalRecursion' and I get the same error.

This setup with .htaccess works correctly if I configure test.localdev as a normal apache vhost. However defeats the purpose of a single dynamic virtual hosts configuration.


Has anybody has success with dynamic virtual hosts and .htaccess rewrite?
Oh I have also tried placing the modrewrite rules directly into the apache configuration (no .htaccess) and its still the same.

Hope someone can help!

Kind Regards,
Dave

d_t_baker 08-16-2007 07:32 PM

Event weirder I get this in my error logs when I access http://test.localdev/pages/foo

Code:

[Fri Aug 17 10:13:15 2007] [error] [client 192.168.1.50] File does not exist: /var/www/test/var
this is with mod vhost_alias and the following .htaccess file in /var/www/test/:

Code:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/page.*$
RewriteRule ^(.*)$ /var/www/test/index.php

and I get a 404 result in the browser:

Code:

Not Found

The requested URL /var/www/test/index.php was not found on this server.

looking at http://test.localdev/ works and displays index.php correctly because the .htaccess rule does not match.

why would it be looking for /var/www/test/var ?? when I create the file /var/www/test/var and put some text in it, that text gets displayed when I load http://test.localdev/pages/foo O__o weird!!!


again here is the file in /etc/apache2/sites-enabled/dynamic_vhosts
I have tried this on two different apache2 installs and I get the same result both times.. what am i doing wrong ??

Code:

<VirtualHost *>
        ServerName localdev
        ServerAlias *.localdev

        VirtualDocumentRoot /var/www/%-2+/

        <Directory /var/www>
                Options Indexes FollowSymLinks
                AllowOverride All
        </Directory>
        <Directory /var/www/%-2+>
                Options Indexes FollowSymLinks
                AllowOverride All
        </Directory>


        ErrorLog /var/log/apache2/error.log

        LogLevel debug

        CustomLog /var/log/apache2/access.log combined
        ServerSignature On

</VirtualHost>

Any ideas?


All times are GMT -5. The time now is 11:42 AM.