Apache mod_rewrite multiple add path info postfix

If you are having strange problems with Apache mod_rewrite, make sure to disable MultiViews with Options -MultiViews (you don’t need it most of the times anyway).

My rewrite rule was something like this:

# /product/WhatEver.php -> /product.php?k=WhatEver
# /product/WhatEver.php?id=12345 -> /product.php?id=12345&k=WhatEver
RewriteRule  ^product/([^/]+)\.php$    product.php?k=$1 [QSA,L]

Found out this after a lot of debugging and searching around the web. First, I enabled mod_rewrite debugging adding these directives:

RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 3

In the log file I found something like:

(3) [perdir /var/www/] add path info postfix: /var/www/product.php -> /var/www/product.php/Test__Test.php
(3) [perdir /var/www/] strip per-dir prefix: /var/www/product.php/Test__Test.php -> product.php/Test__Test.php
(3) [perdir /var/www/] applying pattern '^([0-9]+)/([^/]+)\.php$' to uri 'product.php/Test__Test.php'
(3) [perdir /var/www/] add path info postfix: /var/www/product.php -> /var/www/product.php/Test__Test.php
(3) [perdir /var/www/] strip per-dir prefix: /var/www/product.php/Test__Test.php -> product.php/Test__Test.php
(3) [perdir /var/www/] applying pattern '^prodotto/([^/]+)\.php$' to uri 'product.php/Test__Test.php'
(3) [perdir /var/www/] add path info postfix: /var/www/product.php -> /var/www/product.php/Test__Test.php
(3) [perdir /var/www/] strip per-dir prefix: /var/www/product.php/Test__Test.php -> product.php/Test__Test.php
(3) [perdir /var/www/] applying pattern '^prodotto/([^/]+)\.php?id=([0-9]+)$' to uri 'product.php/Test__Test.php'
(3) [perdir /var/www/] add path info postfix: /var/www/product.php -> /var/www/product.php/Test__Test.php
(3) [perdir /var/www/] strip per-dir prefix: /var/www/product.php/Test__Test.php -> product.php/Test__Test.php
(3) [perdir /var/www/] applying pattern '^c/([^/]+)/([^/]+)\.php$' to uri 'product.php/Test__Test.php'
(1) [perdir /var/www/] pass through /var/www/product.php

The problem was that the request was being modified by MultiViews, substituting /product/ with /product.php and never triggering the mod_rewrite rule.

Advertisements

2 thoughts on “Apache mod_rewrite multiple add path info postfix

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s