[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Apache, mod_rewrite and directory context



Hi,

I'm trying to pass everything that is not a file to `index.php` as a
request parameter without using a `.htaccess` file.

A request to http://www.example.com/test must be rewritten to
http://www.example.com/index.php?q=/test.

I'm using Debian Squeeze (6.0) and Apache 2.2.16. Here is my
configuration file:

<VirtualHost *:80>
  DocumentRoot /var/www/example
  ServerName www.example.com
  ServerAlias example.com

  ErrorLog /var/log/apache2/error/example.log
  CustomLog /var/log/apache2/access/example.log combined

  <IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
    RewriteRule ^/(.*) http://www.example.com/$1 [L,R=301]
  </IfModule>

  <Directory "/var/www/test">
    AllowOverride None
    Options -Indexes +FollowSymLinks
    DirectoryIndex index.php

    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteCond %{REQUEST_URI} !=/favicon.ico
      RewriteRule ^/(.*)$ index.php?q=$1 [L,QSA]
    </IfModule>
  </Directory>
</VirtualHost>

The first call to `mod_rewrite` within the _VirtualHost_ scope will as
expected change example.com to www.example.com. But, the second call in
the _Directory_ does not seems to work and calling
http://www.example.com/test will throw a 404 error.

Here is the result in the log file:

(2) init rewrite engine with requested uri /test
(3) applying pattern '^/(.*)' to uri '/test'
(4) RewriteCond: input='www.example.com' pattern='!^www\.example\.com
$' [NC] => not-matched
(1) pass through /test
(3) [perdir /var/www/example/] strip per-dir
prefix: /var/www/example/test -> test
(3) [perdir /var/www/example/] applying pattern '^/(.*)$' to uri 'test'
(1) [perdir /var/www/example/] pass through /var/www/test/test
File does not exist: /var/www/test/test

What did I miss?

--
Jimmy


Reply to: