htaccess re-applies a matched rule constantly and ends up in a loop - apache

According to http://htaccess.madewithlove.be/ the following ruleset works perfectly:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^images/([^\?]+)$ /_lib/mask_images.php [L]
RewriteRule ^search/([^\?]+)/merchant/([^\?]+)/brand/([^\?]+)/page/([^\?]+)$ /search.php?keyword=$1&merchant=$2&brand=$3&page=$4 [L]
RewriteRule ^search/([^\?]+)/brand/([^\?]+)/page/([^\?]+)$ /search.php?keyword=$1&brand=$2&page=$3 [L]
RewriteRule ^search/([^\?]+)/merchant/([^\?]+)/page/([^\?]+)$ /search.php?keyword=$1&merchant=$2&page=$3 [L]
RewriteRule ^search/([^\?]+)/page/([^\?]+)$ /search.php?keyword=$1&page=$2 [L]
RewriteRule ^search/([^\?]+)/brand/([^\?]+)$ /search.php?keyword=$1&brand=$2 [L]
RewriteRule ^search/([^\?]+)/merchant/([^\?]+)$ /search.php?keyword=$1&merchant=$2 [L]
RewriteRule ^search/([^\?]+)/merchant/([^\?]+)/brand/([^\?]+)$ /search.php?keyword=$1&merchant=$2&brand=$3 [L]
RewriteRule ^search/([^\?]+)$ /search.php?keyword=$1 [L]
RewriteRule ([^\?]+)/productID/([^\?]+)$ /detail.php?keyword=$1&productID=$2 [L]
RewriteRule ([^\?]+)$ /detail.php?keyword=$1 [L]
The issue is that when the last 2 rules are applied and matched, Apache re-applies the matched rules (and correctly assigned arguments) and goes into an infinite loop.
I added:
RewriteCond %{REQUEST_URI} !search.php$
RewriteCond %{REQUEST_URI} !detail.php$
RewriteCond %{REQUEST_URI} !index.php$
to the above ruleset. Again, verified and working by the htaccess tester website, it now stops processing and outputs "detail.php" as the argument.
Here is what the Rewrite Log says:
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/hello -> hello
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] applying pattern '^images/(.*)$' to uri 'hello'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/hello -> hello
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] applying pattern '^search/(.*)/merchant/(.*)/brand/(.*)/page/(.*)$' to uri 'hello'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/hello -> hello
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] applying pattern '^search/(.*)/brand/(.*)/page/(.*)$' to uri 'hello'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/hello -> hello
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] applying pattern '^search/(.*)/merchant/(.*)/page/(.*)$' to uri 'hello'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/hello -> hello
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] applying pattern '^search/(.*)/page/(.*)$' to uri 'hello'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/hello -> hello
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] applying pattern '^search/(.*)/brand/(.*)$' to uri 'hello'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/hello -> hello
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] applying pattern '^search/(.*)/merchant/(.*)$' to uri 'hello'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/hello -> hello
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] applying pattern '^search/(.*)/merchant/(.*)/brand/(.*)$' to uri 'hello'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/hello -> hello
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] applying pattern '^search/(.*)$' to uri 'hello'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/hello -> hello
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] applying pattern '(.*)/productID/(.*)$' to uri 'hello'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/hello -> hello
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) [perdir /var/www/html/] applying pattern '(.*)$' to uri 'hello'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (2) [perdir /var/www/html/] rewrite 'hello' -> '/detail.php?keyword=hello'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (3) split uri=/detail.php?keyword=hello -> uri=/detail.php, args=keyword=hello
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (2) [perdir /var/www/html/] trying to replace prefix /var/www/html/ with /
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaabfcc50/initial] (1) [perdir /var/www/html/] internal redirect with /detail.php [INTERNAL REDIRECT]
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/detail.php -> detail.php
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^images/(.*)$' to uri 'detail.php'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/detail.php -> detail.php
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^search/(.*)/merchant/(.*)/brand/(.*)/page/(.*)$' to uri 'detail.php'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/detail.php -> detail.php
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^search/(.*)/brand/(.*)/page/(.*)$' to uri 'detail.php'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/detail.php -> detail.php
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^search/(.*)/merchant/(.*)/page/(.*)$' to uri 'detail.php'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/detail.php -> detail.php
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^search/(.*)/page/(.*)$' to uri 'detail.php'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/detail.php -> detail.php
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^search/(.*)/brand/(.*)$' to uri 'detail.php'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/detail.php -> detail.php
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^search/(.*)/merchant/(.*)$' to uri 'detail.php'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/detail.php -> detail.php
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^search/(.*)/merchant/(.*)/brand/(.*)$' to uri 'detail.php'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/detail.php -> detail.php
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '^search/(.*)$' to uri 'detail.php'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/detail.php -> detail.php
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '(.*)/productID/(.*)$' to uri 'detail.php'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] strip per-dir prefix: /var/www/html/detail.php -> detail.php
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) [perdir /var/www/html/] applying pattern '(.*)$' to uri 'detail.php'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (2) [perdir /var/www/html/] rewrite 'detail.php' -> '/detail.php?keyword=detail.php'
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (3) split uri=/detail.php?keyword=detail.php -> uri=/detail.php, args=keyword=detail.php
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (2) [perdir /var/www/html/] trying to replace prefix /var/www/html/ with /
192.168.0.2 - - [11/Nov/2011:08:54:27 +0200] [website1.co.za/sid#2afe7a520d70][rid#2aaaaac0e0c0/initial/redir#1] (1) [perdir /var/www/html/] internal redirect with /detail.php [INTERNAL REDIRECT]
As you can see, it matches the correct rule and the arguments are setup correctly, but for some reason it then RE-APPLIES that internal redirect again and the argument going through changes from what it should be (which, in this example is "hello") to the file name, detail.php
NO idea how to go about this since everything I know of currently, this should be working because /search works brilliantly.
EDIT
This is what detail.php contains:
<?
echo $_GET["keyword"]."<br>";
echo $_GET["merchant"]."<br>";
echo $_GET["brand"]."<br>";
echo $_GET["page"]."<br>";
echo $_GET["productID"]."<br>";
exit();
?>

The final [L] to /detail.php does an (internal) redirect. And hence Apache sees a totally new request coming in - re-applying the rules ones more.
So options may be to make sure that the rule does not apply to the /detail.php (i.e. by ensuring the argument name is a bit different) or pre-cathcing an ^/detail.php early and negating out.
http://www.sitepoint.com/mod_rewrite-no-endless-loops/ tries to explain this with different words. Another common approach is using things like:
# Loop stopping snippets.
# Uncomment if there are specific pages to exempt.
# RewriteCond %{REQUEST_URI} ^/(stats/|missing\.html|failed_auth\.html|error/).* [NC]
# RewriteRule .* - [L]
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
where you detect this on the second pass (after the internal redirect) and have it bail in a generic way early.
Dw.

Your indentation does not reflect the semantic association of the RewriteRule and RewriteCond directives.
The conditions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
only apply if the URI pattern is ^images/([^\?]+)$. What you need is logically flip this and or at least skip the 10 following rules for these to apply for all URI patterns:
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule . - [SKIP=10]
See my article More on using Rewrite rules in .htaccess files for more details.

Related

Apache mod_rewrite redirecting to base URL

I'm busy migrating a production codeigniter project to a new server. The current setup has been working fine for almost a year now but while moving to the new LAMP stack I'm running into a weird problem with rewriting the index.php back into the URL.
This is the mod_rewrite is as follows
RewriteEngine On
RewriteBase /bookings/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Like I said this has been working fine in the current setup however on the new server links from the base page always are rewritten to the same page. Both servers run Debian 7.5 and Apache 2.2.22
I turned rewrite logging on for both servers and the new server is doing an extra rewrite step that I cannot explain.
Current server:
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] add path info postfix: /var/www/vhosts/domain.tld/html/bookings/school -> /var/www/vhosts/domain.tld/html/bookings/school/event/1
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] strip per-dir prefix: /var/www/vhosts/domain.tld/html/bookings/school/event/1 -> school/event/1
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] applying pattern '^(.*)$' to uri 'school/event/1'
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/school' pattern='!-f' => matched
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/school' pattern='!-d' => matched
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (2) [perdir /var/www/vhosts/domain.tld/html/bookings/] rewrite 'school/event/1' -> 'index.php/school/event/1'
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] add per-dir prefix: index.php/school/event/1 -> /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (2) [perdir /var/www/vhosts/domain.tld/html/bookings/] trying to replace prefix /var/www/vhosts/domain.tld/html/bookings/ with /bookings/
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (5) strip matching prefix: /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1 -> index.php/school/event/1
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (4) add subst prefix: index.php/school/event/1 -> /bookings/index.php/school/event/1
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5c45350a0/initial] (1) [perdir /var/www/vhosts/domain.tld/html/bookings/] internal redirect with /bookings/index.php/school/event/1 [INTERNAL REDIRECT]
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5b3e057c8/initial/redir#1] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] add path info postfix: /var/www/vhosts/domain.tld/html/bookings/index.php -> /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5b3e057c8/initial/redir#1] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] strip per-dir prefix: /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1 -> index.php/school/event/1
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5b3e057c8/initial/redir#1] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] applying pattern '^(.*)$' to uri 'index.php/school/event/1'
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5b3e057c8/initial/redir#1] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/index.php' pattern='!-f' => not-matched
105.237.x.x - - [16/May/2014:09:45:11 +0200] [www.domain.tld/sid#7fd5c46fbfc8][rid#7fd5b3e057c8/initial/redir#1] (1) [perdir /var/www/vhosts/domain.tld/html/bookings/] pass through /var/www/vhosts/domain.tld/html/bookings/index.php
New server:
### First section is identical ###
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] add path info postfix: /var/www/vhosts/domain.tld/html/bookings/school -> /var/www/vhosts/domain.tld/html/bookings/school/event/1
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] strip per-dir prefix: /var/www/vhosts/domain.tld/html/bookings/school/event/1 -> school/event/1
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] applying pattern '^(.*)$' to uri 'school/event/1'
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/school' pattern='!-f' => matched
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/school' pattern='!-d' => matched
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (2) [perdir /var/www/vhosts/domain.tld/html/bookings/] rewrite 'school/event/1' -> 'index.php/school/event/1'
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] add per-dir prefix: index.php/school/event/1 -> /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (2) [perdir /var/www/vhosts/domain.tld/html/bookings/] trying to replace prefix /var/www/vhosts/domain.tld/html/bookings/ with /bookings/
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (5) strip matching prefix: /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1 -> index.php/school/event/1
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (4) add subst prefix: index.php/school/event/1 -> /bookings/index.php/school/event/1
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673240a0/initial] (1) [perdir /var/www/vhosts/domain.tld/html/bookings/] internal redirect with /bookings/index.php/school/event/1 [INTERNAL REDIRECT]
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f3367321b58/initial/redir#1] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] add path info postfix: /var/www/vhosts/domain.tld/html/bookings/index.php -> /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f3367321b58/initial/redir#1] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] strip per-dir prefix: /var/www/vhosts/domain.tld/html/bookings/index.php/school/event/1 -> index.php/school/event/1
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f3367321b58/initial/redir#1] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] applying pattern '^(.*)$' to uri 'index.php/school/event/1'
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f3367321b58/initial/redir#1] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/index.php' pattern='!-f' => not-matched
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f3367321b58/initial/redir#1] (1) [perdir /var/www/vhosts/domain.tld/html/bookings/] pass through /var/www/vhosts/domain.tld/html/bookings/index.php
### The extra redirect ###
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673220a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] strip per-dir prefix: /var/www/vhosts/domain.tld/html/bookings/ ->
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673220a0/initial] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] applying pattern '^(.*)$' to uri ''
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673220a0/initial] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/' pattern='!-f' => matched
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673220a0/initial] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/' pattern='!-d' => not-matched
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f33673220a0/initial] (1) [perdir /var/www/vhosts/domain.tld/html/bookings/] pass through /var/www/vhosts/domain.tld/html/bookings/
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f336731c0a0/subreq] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] strip per-dir prefix: /var/www/vhosts/domain.tld/html/bookings/index.php -> index.php
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f336731c0a0/subreq] (3) [perdir /var/www/vhosts/domain.tld/html/bookings/] applying pattern '^(.*)$' to uri 'index.php'
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f336731c0a0/subreq] (4) [perdir /var/www/vhosts/domain.tld/html/bookings/] RewriteCond: input='/var/www/vhosts/domain.tld/html/bookings/index.php' pattern='!-f' => not-matched
105.237.x.x - - [16/May/2014:10:11:18 +0200] [www.domain.tld/sid#7f33674c04f0][rid#7f336731c0a0/subreq] (1) [perdir /var/www/vhosts/domain.tld/html/bookings/] pass through /var/www/vhosts/domain.tld/html/bookings/index.php
As can be seen above, the new server is doing the initial redirect correctly but then there's the extra section that always returns index.php. Any idea what could be causing this? I'm not even 100% sure that they problem is with mod_rewrite. I've run out of options and I don't know much about mod_rewrite
I have no idea what caused this but I reimaged the server, reinstalled the services and the problem went away.

Why Apache mod_rewrite rewrites twice my URL?

I need to rewrite /admin/page/create URL to /backend/www/index.php/page/create, so I use the next Apache rewrite rule and conditions:
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteCond %{REQUEST_URI} !backend\/www
RewriteRule admin\/(.*)$ backend/www/index.php/$1 [NS,L]
However, examining the rewrite log, I see Apache rewrites correctly the URL, but at the end it performs an additional rewrite considering /page/create URL, which doesn't match any condition, so it fails and I receive the "No input file specified." error.
How can I prevent Apache to perform that additional rewrite? I used NS flag and RewriteCond %{IS_SUBREQ} f condition and it also performs the subrequest.
Thank you!
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (2) init rewrite engine with requested uri /admin/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (1) pass through /admin/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (3) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] add path info postfix: /home/daniloaz/dev.daniloaz.com/httpdocs/admin -> /home/daniloaz/dev.daniloaz.com/httpdocs/admin/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (3) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] strip per-dir prefix: /home/daniloaz/dev.daniloaz.com/httpdocs/admin/page/create -> admin/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (3) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] applying pattern 'admin\/(.*)$' to uri 'admin/page/create'
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (4) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] RewriteCond: input='/admin/page/create' pattern='!-f' => matched
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (4) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] RewriteCond: input='/admin/page/create' pattern='!-d' => matched
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (4) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] RewriteCond: input='/admin/page/create' pattern='!backend\/www' => matched
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (4) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] RewriteCond: input='/admin/page/create' pattern='((admin\/(.*)$)|(admin$))' => matched
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (4) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] RewriteCond: input='false' pattern='f' => matched
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (2) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] rewrite 'admin/page/create' -> 'backend/www/index.php/page/create'
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (3) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] add per-dir prefix: backend/www/index.php/page/create -> /home/daniloaz/dev.daniloaz.com/httpdocs/backend/www/index.php/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (2) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] strip document_root prefix: /home/daniloaz/dev.daniloaz.com/httpdocs/backend/www/index.php/page/create -> /backend/www/index.php/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a35d60/initial] (1) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] internal redirect with /backend/www/index.php/page/create [INTERNAL REDIRECT]
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a472f0/initial/redir#1] (2) init rewrite engine with requested uri /backend/www/index.php/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a472f0/initial/redir#1] (1) pass through /backend/www/index.php/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a472f0/initial/redir#1] (3) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] add path info postfix: /home/daniloaz/dev.daniloaz.com/httpdocs/backend/www/index.php -> /home/daniloaz/dev.daniloaz.com/httpdocs/backend/www/index.php/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a472f0/initial/redir#1] (3) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] strip per-dir prefix: /home/daniloaz/dev.daniloaz.com/httpdocs/backend/www/index.php/page/create -> backend/www/index.php/page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a472f0/initial/redir#1] (3) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] applying pattern 'admin\/(.*)$' to uri 'backend/www/index.php/page/create'
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a472f0/initial/redir#1] (1) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] pass through /home/daniloaz/dev.daniloaz.com/httpdocs/backend/www/index.php
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a4ce60/subreq] (2) init rewrite engine with requested uri /page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a4ce60/subreq] (1) pass through /page/create
80.29.4.44 - - [13/Jun/2013:21:40:54 +0200] [dev.daniloaz.com/sid#7f65e59b6a78][rid#7f65e5a4ce60/subreq] (1) [perdir /home/daniloaz/dev.daniloaz.com/httpdocs/] pass through /home/daniloaz/dev.daniloaz.com/httpdocs/page
Well, I finally solved this issue using a workaround. First I tried these solutions, but subrequests were performed again and again and rewriting failed as before.
With mod_rewrite, there are small differences if you put a rule in .htaccess or in global configuration (httpd.conf, Virtualhost configuration, etc.). Subrequests are one of that differences. Just place the same rule I mentioned above in Virtualhost config file instead of .htaccess and subqueries stop and everything starts working like a charm.
I recommend this useful post to fully understand the internals of mod_rewrite before trying to solve any related to it issue: http://net.tutsplus.com/tutorials/other/a-deeper-look-at-mod_rewrite-for-apache/
I just want to drop my experience here in case somebody reaches the same point I did:
I had the same problem. I tried every single answer. Every single solution. Up to the level when I can say "I really fully understand the rewrite engine". But nothing works. My URLs were still changing and showing the query string.
In some moment I said: "This is likely improbable. Must be something else". And then I tried to get the URL with WGET instead of the browser (firefox).
I did:
wget -qSO http://MY-THING
And then I realized that NOTHING from the server said the URL I saw in the browser's address bar. And even better, NOTHING in the log file!
So... how and why does it change? The obvious answer is "the browser"
I tried another browser (chrome) and works!
So what I did was to clean the history with the "forget this site" option and everybody happy.
Now I don't know WHEN I fixed it. Might be the -Multiviews thing, or the rule's flags, or the INTERNAL REDIRECT part... I don't really know. But probably the solution wasn't there.

Conditionally redirecting traffic with mod_rewrite dependent on protocol

I've been writing a rewrite rule to try and redirect all of our traffic from mysite.com.au to www.mysite.com.au. I also need to conditionally redirect depending on SSL enabled or not.
I've hacked on a bit from askapache.com to create a variable that holds either http or https dependently. Below is the code I'm using:
RewriteCond %{HTTPS} =on
RewriteRule ^(.+)$ - [env=ps:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.+)$ - [env=ps:http]
RewriteCond %{HTTP_HOST} ^mysite\.com\.au(.*)$ [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*)$ %{ENV:ps}://www.mysite.com.au/$1 [L,R=301]
This works fine for URLs with paths (e.g. mysite.com.au/foo redirects to www.mysite.com.au/foo) and does the http and https switch fine.
However when just accessing the domain (just mysite.com.au) it redirects to http://www.mysite.com.au/home/website/public_html/:/www.mysite.com.au/
I'm sure it's something very small and basic I'm missing - if someone could point it out, that'd be appreciated.
Thanks!
Andrew
I've found an answer - it's nothing like what it seems from first glance.
I turned on RewriteLog and I identified the problem. In the logs if I am using my original condition/rule and use mysite.com.au/test I see the following:
10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/test -> test
10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.+)$' to uri 'test'
10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/test -> test
10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.+)$' to uri 'test'
10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/test -> test
10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.*)$' to uri 'test'
10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (2) [perdir /home/website/public_html/] rewrite 'test' -> 'http://www.mysite.com.au/test'
10.1.1.1 - - [11/Feb/2013:11:37:50 +1100] [mysite.com.au/sid#b81d24f8][rid#b847d100/initial] (2) [perdir /home/website/public_html/] explicitly forcing redirect with http://www.mysite.com.au/test
However when I run it against just mysite.com.au I see:
10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/ ->
10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.+)$' to uri ''
10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/ ->
10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.+)$' to uri ''
10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/ ->
10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.*)$' to uri ''
10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (2) [perdir /home/website/public_html/] rewrite '' -> '://www.mysite.com.au/'
10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (3) [perdir /home/website/public_html/] add per-dir prefix: ://www.mysite.com.au/ -> /home/website/public_html/://www.mysite.com.au/
10.1.1.1 - - [11/Feb/2013:11:38:16 +1100] [mysite.com.au/sid#b81d24f8][rid#b845bc18/initial] (2) [perdir /home/website/public_html/] explicitly forcing redirect with http:/.makeitmine.com.au/home/website/public_html/://www.mysite.com.au/
Note that the environment variable I’m trying to set (SSL on/off) isn’t being set. As such, it’s not seeing the http/https prefix and assuming it’s a relative internal path!
When I’m trying to set the environment variable, I use the following code:
RewriteCond %{HTTPS} =on
RewriteRule ^(.+)$ - [env=ps:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.+)$ - [env=ps:http]
The RegEx of ^(.+)$ expects a minimum of 1 character, which there is not to match! I modified it as follows:
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ - [env=ps:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ - [env=ps:http]
And now it matches, even on 0 characters!
Thanks again for your help, problem solved :)
10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/ ->
10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.*)$' to uri ''
10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/ ->
10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.*)$' to uri ''
10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (3) [perdir /home/website/public_html/] strip per-dir prefix: /home/website/public_html/ ->
10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (3) [perdir /home/website/public_html/] applying pattern '^(.*)$' to uri ''
10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (2) [perdir /home/website/public_html/] rewrite '' -> 'http://www.mysite.com.au/'
10.1.1.1 - - [11/Feb/2013:11:44:57 +1100] [mysite.com.au/sid#b81d24f8][rid#b8478208/initial] (2) [perdir /home/website/public_html/] explicitly forcing redirect with http://www.mysite.com.au/

Apache rewrite parses URL twice unexpectedly

I'm trying to redirect all the webpages from certain domain names to a specific web application that handles several sites.
I have my web app in a folder "skylight2" and another folder, named "testsite", with only a .htaccess file:
RewriteEngine on
RewriteRule ^(((?!skylight2).)*)$ /home/stefano/webroot_aliases/skylight2/$1/?site=testsite [QSA]
I'm using virtual roots, and my httpd-vroot.conf looks like this:
<VirtualHost *:80>
ServerName webserver
ServerAlias *.webserver
UseCanonicalName Off
VirtualDocumentRoot /home/stefano/webroot_aliases/%1
Options -Indexes FollowSymLinks -MultiViews
RewriteLog "/var/log/httpd/vroot_rewrite.log"
RewriteLogLevel 3
<Directory /home/stefano/webroot_aliases/>
Order allow,deny
Allow from all
AllowOverride FileInfo Indexes Limit Options
RewriteEngine On
RewriteBase /
</Directory>
</VirtualHost>
If I try to access testsite.webserver, I get an "object not found" error. This is my rewrite log:
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#253f320/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/webroot_aliases/testsite/articles -> /home/stefano/webroot_aliases/testsite/articles/view
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#253f320/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/articles/view -> articles/view
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#253f320/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(((?!skylight2).)*)$' to uri 'articles/view'
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#253f320/initial] (2) [perdir /home/stefano/webroot_aliases/testsite/] rewrite 'articles/view' -> '/home/stefano/webroot_aliases/skylight2/articles/view/?site=testsite'
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#253f320/initial] (3) split uri=/home/stefano/webroot_aliases/skylight2/articles/view/?site=testsite -> uri=/home/stefano/webroot_aliases/skylight2/articles/view/, args=site=testsite
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#253f320/initial] (1) [perdir /home/stefano/webroot_aliases/testsite/] internal redirect with /home/stefano/webroot_aliases/skylight2/articles/view/ [INTERNAL REDIRECT]
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2531a18/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/webroot_aliases/testsite/home -> /home/stefano/webroot_aliases/testsite/home/stefano/webroot_aliases/skylight2/articles/view/
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2531a18/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/home/stefano/webroot_aliases/skylight2/articles/view/ -> home/stefano/webroot_aliases/skylight2/articles/view/
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2531a18/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(((?!skylight2).)*)$' to uri 'home/stefano/webroot_aliases/skylight2/articles/view/'
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2531a18/initial/redir#1] (1) [perdir /home/stefano/webroot_aliases/testsite/] pass through /home/stefano/webroot_aliases/testsite/home
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#252f2a0/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/favicon.ico -> favicon.ico
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#252f2a0/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(((?!skylight2).)*)$' to uri 'favicon.ico'
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#252f2a0/initial] (2) [perdir /home/stefano/webroot_aliases/testsite/] rewrite 'favicon.ico' -> '/home/stefano/webroot_aliases/skylight2/favicon.ico/?site=testsite'
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#252f2a0/initial] (3) split uri=/home/stefano/webroot_aliases/skylight2/favicon.ico/?site=testsite -> uri=/home/stefano/webroot_aliases/skylight2/favicon.ico/, args=site=testsite
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#252f2a0/initial] (1) [perdir /home/stefano/webroot_aliases/testsite/] internal redirect with /home/stefano/webroot_aliases/skylight2/favicon.ico/ [INTERNAL REDIRECT]
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2533830/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/webroot_aliases/testsite/home -> /home/stefano/webroot_aliases/testsite/home/stefano/webroot_aliases/skylight2/favicon.ico/
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2533830/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/home/stefano/webroot_aliases/skylight2/favicon.ico/ -> home/stefano/webroot_aliases/skylight2/favicon.ico/
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2533830/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(((?!skylight2).)*)$' to uri 'home/stefano/webroot_aliases/skylight2/favicon.ico/'
127.0.0.1 - - [08/Mar/2012:07:56:23 --0600] [testsite.webserver/sid#21f2ca0][rid#2533830/initial/redir#1] (1) [perdir /home/stefano/webroot_aliases/testsite/] pass through /home/stefano/webroot_aliases/testsite/home
Apparently, the URL is parsed once (correctly), and then the second time where it's added the prefix again, resulting in an error. Unfortunately, I cannot put a [L] flag to this rule because the URL gets parsed further in the application folder.
Can anybody explain to me what is happening?
Thanks
gm
EDIT: I applied the rule:
RewriteRule ^(?!skylight2)(.*)$ skylight2/$1/?site=testsite [QSA,L]
And get this:
127.0.0.1 - - [09/Mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#1951280/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/webroot_a
liases/testsite/articles -> /home/stefano/webroot_aliases/testsite/articles/view
127.0.0.1 - - [09/Mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#1951280/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_al
iases/testsite/articles/view -> articles/view
127.0.0.1 - - [09/Mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#1951280/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(?!skylight2)(.*)$' to uri
'articles/view'
127.0.0.1 - - [09/Mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#1951280/initial] (2) [perdir /home/stefano/webroot_aliases/testsite/] rewrite 'articles/view' -> 'skylight2/articles
/view/?site=testsite'
127.0.0.1 - - [09/Mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#1951280/initial] (3) split uri=skylight2/articles/view/?site=testsite -> uri=skylight2/articles/view/, args=site=tes
tsite
127.0.0.1 - - [09/Mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#1951280/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] add per-dir prefix: skylight2/articles/view/ -
> /home/stefano/webroot_aliases/testsite/skylight2/articles/view/
127.0.0.1 - - [09/Mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#1951280/initial] (1) [perdir /home/stefano/webroot_aliases/testsite/] internal redirect with /home/stefano/webroot_a
liases/testsite/skylight2/articles/view/ [INTERNAL REDIRECT]
127.0.0.1 - - [09/Mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#195c9e0/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/w
ebroot_aliases/testsite/home -> /home/stefano/webroot_aliases/testsite/home/stefano/webroot_aliases/testsite/skylight2/articles/view/
127.0.0.1 - - [09/Mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#195c9e0/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/we
broot_aliases/testsite/home/stefano/webroot_aliases/testsite/skylight2/articles/view/ -> home/stefano/webroot_aliases/testsite/skylight2/articles/view/
127.0.0.1 - - [09/Mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#195c9e0/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(?!skylight2)(.*)$'
to uri 'home/stefano/webroot_aliases/testsite/skylight2/articles/view/'
127.0.0.1 - - [09/Mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#195c9e0/initial/redir#1] (2) [perdir /home/stefano/webroot_aliases/testsite/] rewrite 'home/stefano/webroot_aliases/
testsite/skylight2/articles/view/' -> 'skylight2/home/stefano/webroot_aliases/testsite/skylight2/articles/view//?site=testsite'
127.0.0.1 - - [09/Mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#195c9e0/initial/redir#1] (3) split uri=skylight2/home/stefano/webroot_aliases/testsite/skylight2/articles/view//?sit
e=testsite -> uri=skylight2/home/stefano/webroot_aliases/testsite/skylight2/articles/view//, args=site=testsite&site=testsite
127.0.0.1 - - [09/Mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#195c9e0/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] add per-dir prefix: skylight2/home/ste
fano/webroot_aliases/testsite/skylight2/articles/view// -> /home/stefano/webroot_aliases/testsite/skylight2/home/stefano/webroot_aliases/testsite/skylight2/articles/view//
127.0.0.1 - - [09/Mar/2012:07:22:45 --0600] [testsite.webserver/sid#161fca0][rid#195c9e0/initial/redir#1] (1) [perdir /home/stefano/webroot_aliases/testsite/] internal redirect with /home/stefano/w
ebroot_aliases/testsite/skylight2/home/stefano/webroot_aliases/testsite/skylight2/articles/view// [INTERNAL REDIRECT]
And so on in an infinite loop.
Why does apache keep adding the path info? Neither L nor DPI flags work.
EDIT #2
Following TerryE's advice I used this config:
RewriteEngine On
RewriteBase /testsite
RewriteRule ^(?!skylight2)(.*)$ /skylight2/$1?site=testsite [QSA,L]
And got this:
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#2d6a740/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/webroot_aliases/testsite/articles -> /home/stefano/webroot_aliases/testsite/articles/view
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#2d6a740/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/articles/view -> articles/view
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#2d6a740/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(?!skylight2)(.*)$' to uri 'articles/view'
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#2d6a740/initial] (2) [perdir /home/stefano/webroot_aliases/testsite/] rewrite 'articles/view' -> '/skylight2/articles/view?site=testsite'
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#2d6a740/initial] (3) split uri=/skylight2/articles/view?site=testsite -> uri=/skylight2/articles/view, args=site=testsite
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#2d6a740/initial] (2) [perdir /home/stefano/webroot_aliases/testsite/] trying to replace prefix /home/stefano/webroot_aliases/testsite/ with /testsite
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#2d6a740/initial] (1) [perdir /home/stefano/webroot_aliases/testsite/] internal redirect with /skylight2/articles/view [INTERNAL REDIRECT]
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a9968/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/webroot_aliases/testsite/skylight2 -> /home/stefano/webroot_aliases/testsite/skylight2/articles/view
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a9968/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/skylight2/articles/view -> skylight2/articles/view
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a9968/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(?!skylight2)(.*)$' to uri 'skylight2/articles/view'
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a9968/initial/redir#1] (1) [perdir /home/stefano/webroot_aliases/testsite/] pass through /home/stefano/webroot_aliases/testsite/skylight2
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18b1290/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/favicon.ico -> favicon.ico
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18b1290/initial] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(?!skylight2)(.*)$' to uri 'favicon.ico'
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18b1290/initial] (2) [perdir /home/stefano/webroot_aliases/testsite/] rewrite 'favicon.ico' -> '/skylight2/favicon.ico?site=testsite'
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18b1290/initial] (3) split uri=/skylight2/favicon.ico?site=testsite -> uri=/skylight2/favicon.ico, args=site=testsite
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18b1290/initial] (2) [perdir /home/stefano/webroot_aliases/testsite/] trying to replace prefix /home/stefano/webroot_aliases/testsite/ with /testsite
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18b1290/initial] (1) [perdir /home/stefano/webroot_aliases/testsite/] internal redirect with /skylight2/favicon.ico [INTERNAL REDIRECT]
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a96f0/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] add path info postfix: /home/stefano/webroot_aliases/testsite/skylight2 -> /home/stefano/webroot_aliases/testsite/skylight2/favicon.ico
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a96f0/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] strip per-dir prefix: /home/stefano/webroot_aliases/testsite/skylight2/favicon.ico -> skylight2/favicon.ico
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a96f0/initial/redir#1] (3) [perdir /home/stefano/webroot_aliases/testsite/] applying pattern '^(?!skylight2)(.*)$' to uri 'skylight2/favicon.ico'
127.0.0.1 - - [10/Mar/2012:08:16:58 --0600] [testsite.webserver/sid#1575ca0][rid#18a96f0/initial/redir#1] (1) [perdir /home/stefano/webroot_aliases/testsite/] pass through /home/stefano/webroot_aliases/testsite/skylight2
Apache throws a "File does not exist: /home/stefano/webroot_aliases/testsite/skylight2" error. The correct URL should be instead /home/stefano/webroot_aliases/skylight2/articles/view.
Could it be because the VirtualDocumentRoot is set to testsite and I can't get out of it once it's set?
By the way, I'm using Apache 2.2.22.
EDIT #3
I actually solved it by placing a symlink "skylight2" in testsite, pointing to "../skylight2". thanks for the help!!
I've come across this bug before and there was an old bugrep on it which fizzled out. It can occur if you do a fall-through on a Per Directory context. But since the rewrite engine loops over the htaccess files anyway, the [L] doesn't mean last it really means "restart loop".
Next your rewrite rule is wrong since your document root is home/stefano/webroot_aliases and rule targets are in URI space not file space so your target should just be skylight2/$1/?site=testsite.
Next the Negative lookahead assertion should not be inside the (.*) loop, so try:
RewriteRule ^(?!skylight2)(.*)$ skylight2/$1/?site=testsite [QSA,L]
If this doesn't work, then append the new rewrite.log extract. Thanks.
Update following comments
The rewrite log shows a DOCROOT of /home/stefano/webroot_aliases/testsite and redirects
articles/view -> testsite/skylight2/articles/view/?site=testsite
Which fails the negative lookahead and loops again, so this is a case when you do need the leading / on the replacement string:
RewriteBase /testsite
RewriteRule ^(?!skylight2)(.*)$ /skylight2/$1/?site=testsite [QSA,L]

Apache Mod Rewrite does not rewrite file name

i have the following problem:
On the download dialog on each browser it displays me only the dot extension filename
like .divx
But i want the full name eg
http://example.com/14558/.divx rewrites to 14558.divx and not onyly .divx
I want see on every browser dialog the number and the extension.
like 14558.divx
How i can solve this problem ??
RewriteRule ^([0-9]+)/.divx$ $1.divx
RewriteRule ^([0-9]+)/.mkv$ $1.mkv
RewriteRule ^([0-9]+)/.avi$ $1.avi
Current Configuration:
RewriteRule ^([0-9]+)/\.(divx|mkv|avi)$ /$1.$2
Rewrite Log:
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae5c7c8/initial] (3) [perdir F:/media/video_files/] add path info postfix: F:/media/video_files/29 -> F:/media/video_files/29/.mkv
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae5c7c8/initial] (3) [perdir F:/media/video_files/] strip per-dir prefix: F:/media/video_files/29/.mkv -> 29/.mkv
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae5c7c8/initial] (3) [perdir F:/media/video_files/] applying pattern '^([0-9]+)/\.(divx|mkv|avi)$' to uri '29/.mkv'
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae5c7c8/initial] (2) [perdir F:/media/video_files/] rewrite '29/.mkv' -> '/29.mkv'
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae5c7c8/initial] (1) [perdir F:/media/video_files/] internal redirect with /29.mkv [INTERNAL REDIRECT]
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae588f8/initial/redir#1] (3) [perdir F:/media/video_files/] strip per-dir prefix: F:/media/video_files/29.mkv -> 29.mkv
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae588f8/initial/redir#1] (3) [perdir F:/media/video_files/] applying pattern '^([0-9]+)/\.(divx|mkv|avi)$' to uri '29.mkv'
127.0.0.1 - - [19/Dec/2011:13:07:02 +0100] [video.local/sid#4518f8][rid#ae588f8/initial/redir#1] (1) [perdir F:/media/video_files/] pass through F:/media/video_files/29.mkv
Your rewriterules seem ok... err well maybe it's the backslash. By the way you could optimize in a nicer way (not tested):
RewriteRule ^([0-9]+)/\.(divx|mkv|avi)$ /$1.$2
But the only way to solve your problem (= show the whole filename) is to make a full redirect to a URL that has the full filename.
So in your case redirect would mean these rules:
RewriteRule ^([0-9]+)/\.(divx|mkv|avi)$ $1.$2 [QSA,R=301,L]
And that implies that the URLs like "14558.divx" and "1526.mkv" have to be valid and return the file.
Two hints:
Please try to use the RewriteLog directive: it helps you to track down such problems:
# Trace:
# (!) file gets big quickly, remove in prod environments:
RewriteLog "/web/logs/mywebsite.rewrite.log"
RewriteLogLevel 9
RewriteEngine On
My favorite tool to check for regexp:
http://www.quanetic.com/Regex (don't forget to choose ereg(POSIX) instead of preg(PCRE)!)