mod_rewrite END flag not working in httpd 2.4 - apache

The END flag for mod_rewrite in Apache 2.4 does not appear to be working correctly. I have a directory named test with a file test.html. I have placed an .htaccess file in the directory with the following content
RewriteEngine on
RewriteRule ^test$ test.html [NC,QSA,END]
RewriteRule ^$ test.html [NC,QSA,END]
Here is the rewrite log for the request http://localhost.dev/test/
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a56d60/initial] [perdir /var/www/vhosts/test/] strip per-dir prefix: /var/www/vhosts/test/ ->
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a56d60/initial] [perdir /var/www/vhosts/test/] applying pattern '^test$' to uri ''
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a56d60/initial] [perdir /var/www/vhosts/test/] strip per-dir prefix: /var/www/vhosts/test/ ->
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a56d60/initial] [perdir /var/www/vhosts/test/] applying pattern '^$' to uri ''
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a56d60/initial] [perdir /var/www/vhosts/test/] rewrite '' -> 'test.html'
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a56d60/initial] [perdir /var/www/vhosts/test/] add per-dir prefix: test.html -> /var/www/vhosts/test/test.html
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a56d60/initial] [perdir /var/www/vhosts/test/] strip document_root prefix: /var/www/vhosts/test/test.html -> /test/test.html
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a56d60/initial] [perdir /var/www/vhosts/test/] internal redirect with /test/test.html [INTERNAL REDIRECT]
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a44060/subreq] [perdir /var/www/vhosts/test/] strip per-dir prefix: /var/www/vhosts/test/index.php -> index.php
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a44060/subreq] [perdir /var/www/vhosts/test/] applying pattern '^test$' to uri 'index.php'
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a44060/subreq] [perdir /var/www/vhosts/test/] strip per-dir prefix: /var/www/vhosts/test/index.php -> index.php
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a44060/subreq] [perdir /var/www/vhosts/test/] applying pattern '^$' to uri 'index.php'
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a44060/subreq] [perdir /var/www/vhosts/test/] pass through /var/www/vhosts/test/index.php
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a44060/subreq] [perdir /var/www/vhosts/test/] strip per-dir prefix: /var/www/vhosts/test/index.html -> index.html
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a44060/subreq] [perdir /var/www/vhosts/test/] applying pattern '^test$' to uri 'index.html'
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a44060/subreq] [perdir /var/www/vhosts/test/] strip per-dir prefix: /var/www/vhosts/test/index.html -> index.html
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a44060/subreq] [perdir /var/www/vhosts/test/] applying pattern '^$' to uri 'index.html'
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a44060/subreq] [perdir /var/www/vhosts/test/] pass through /var/www/vhosts/test/index.html
Why is mod_rewrite making sub requests for directory index files index.html and index.php, when the second rule matches the request?
Request for http://localhost.dev/test/test works without any sub request, as expected
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a58b20/initial] [perdir /var/www/vhosts/test/] strip per-dir prefix: /var/www/vhosts/test/test -> test
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a58b20/initial] [perdir /var/www/vhosts/test/] applying pattern '^test$' to uri 'test'
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a58b20/initial] [perdir /var/www/vhosts/test/] rewrite 'test' -> 'test.html'
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a58b20/initial] [perdir /var/www/vhosts/test/] add per-dir prefix: test.html -> /var/www/vhosts/test/test.html
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a58b20/initial] [perdir /var/www/vhosts/test/] strip document_root prefix: /var/www/vhosts/test/test.html -> /test/test.html
[...] 10.0.2.2 - - [localhost.dev/sid#2532c00][rid#2a58b20/initial] [perdir /var/www/vhosts/test/] internal redirect with /test/test.html [INTERNAL REDIRECT]
I have tried using L and END flags, independently and together.

It appears mod_dir does not respect the END flag set by mod_rewrite. For anyone else who is experiencing this, I was able to work around the problem with the following
RewriteEngine on
RewriteRule ^$ /test/home.php [NC,QSA,END,E=IS_DIR_INDEX:1]
FallbackResource /test/fallback.php
<If "env('IS_DIR_INDEX') == 1">
SetHandler default_handler
</If>

I hit the same problem on Apache 2.4.7 on Ubuntu and reported a bug to Apache which was confirmed and is fixed in 2.4.9, see here. For Ubuntu, there is an updated PPA here for easy upgrade. If upgrading is not possible or you don't want to compile the sources, you can use Joyce's workaround above, or the one I posted here which uses only RewriteCond and RewriteRule.

Related

Restler not loading any classes

Using Restler 3.0.0-RC6 I'm getting a 404 from Routes.php at route stage. I've turned on rewrite debugging on apache and I see that it's redirecting to /var/www/html/api/public/index.php when I try to load the URL, and that is in fact where the index.php for Restler lives. It's just not loading any of the classes from the src directory though. How do I debug this?
Here's the rewrite rule output:
[perdir /var/www/html/api/] add path info postfix: /var/www/html/api/v2 -> /var/www/html/api/v2/team/details/1/0
[perdir /var/www/html/api/] strip per-dir prefix: /var/www/html/api/v2/team/details/1/0 -> v2/team/details/1/0
[perdir /var/www/html/api/] applying pattern '^$' to uri 'v2/team/details/1/0'
[perdir /var/www/html/api/] add path info postfix: /var/www/html/api/v2 -> /var/www/html/api/v2/team/details/1/0
[perdir /var/www/html/api/] strip per-dir prefix: /var/www/html/api/v2/team/details/1/0 -> v2/team/details/1/0
[perdir /var/www/html/api/] applying pattern '^(.*)$' to uri 'v2/team/details/1/0'
[perdir /var/www/html/api/] RewriteCond: input='/var/www/html/api/v2' pattern='!-f' => matched
[perdir /var/www/html/api/] RewriteCond: input='/var/www/html/api/v2' pattern='!-d' => matched
[perdir /var/www/html/api/] rewrite 'v2/team/details/1/0' -> 'public/index.php'
[perdir /var/www/html/api/] add per-dir prefix: public/index.php -> /var/www/html/api/public/index.php
[perdir /var/www/html/api/] strip document_root prefix: /var/www/html/api/public/index.php -> /api/public/index.php
[perdir /var/www/html/api/] internal redirect with /api/public/index.php [INTERNAL REDIRECT]
[perdir /var/www/html/api/public/] strip per-dir prefix: /var/www/html/api/public/index.php -> index.php
[perdir /var/www/html/api/public/] applying pattern '^' to uri 'index.php'
[perdir /var/www/html/api/public/] RewriteCond: input='/var/www/html/api/public/index.php' pattern='!-d' => matched
[perdir /var/www/html/api/public/] RewriteCond: input='/var/www/html/api/public/index.php' pattern='!-f' => not-matched
[perdir /var/www/html/api/public/] pass through /var/www/html/api/public/index.php
And as you can see, the index.php is there, and the appropriate class is there:
% ls -l /var/www/html/api/public/index.php
-rw-r--r-- 1 root root 961 Jun 3 21:40 /var/www/html/api/public/index.php
% ls -l /var/www/html/api/src/v2/Team.php
-rw-rwxr-- 1 559 559 19255 May 9 23:02 /var/www/html/api/src/v2/Team.php
I forgot to include the Defaults::$useUrlBasedVersioning = true; line in my index.php so it was always trying to force a v1 version to load, which doesn't exist any longer.

Difference in .htaccess behaviour

I have finished developing a micro app with Phalcon and tried to move it to production server, but have encountered some problems with .htaccess rules.
Directory layout on the serwer is like this :
/var/www
|- .htaccess
|- redmine/
|- wordpress/
|- (other dirs)
|- MyApp/
|- .htaccess
|- public/
|- .htaccess
|- api.php
/var/www/.htaccess :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_URI} !(redmine|MyApp) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
/var/www/MyApp/.htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !(\.gif|\.jpg|\.png|\.mp3|\.ods|\.csv|\.xls)$ [NC]
RewriteRule ^$ public/ [L]
RewriteCond %{REQUEST_URI} !(\.gif|\.jpg|\.png|\.mp3|\.ods|\.csv|\.xls)$ [NC]
RewriteRule (.*) public/$1 [L]
</IfModule>
/var/www/MyApp/public/.htaccess :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ api.php?_url=/$1 [QSA,L]
</IfModule>
I'm really new to all this. The top-most .htaccess was not setup by me, and frankly I don't know what is going on in there. The others are based on Phalcon tutorials.
Everything worked on my local machine, but stopped when I uploaded it. I turned on logging in both places.
Local log :
[perdir /Users/Losiowaty/MyApp/] add path info postfix: /Users/Losiowaty/MyApp/api -> /Users/Losiowaty/MyApp/api/poeci
[perdir /Users/Losiowaty/MyApp/] strip per-dir prefix: /Users/Losiowaty/MyApp/api/poeci -> api/poeci
[perdir /Users/Losiowaty/MyApp/] applying pattern '^$' to uri 'api/poeci'
[perdir /Users/Losiowaty/MyApp/] add path info postfix: /Users/Losiowaty/MyApp/api -> /Users/Losiowaty/MyApp/api/poeci
[perdir /Users/Losiowaty/MyApp/] strip per-dir prefix: /Users/Losiowaty/MyApp/api/poeci -> api/poeci
[perdir /Users/Losiowaty/MyApp/] applying pattern '(.*)' to uri 'api/poeci'
[perdir /Users/Losiowaty/MyApp/] RewriteCond: input='/MyApp/api/poeci' pattern='!(\\.gif|\\.jpg|\\.png|\\.mp3|\\.ods|\\.csv|\\.xls)$' [NC] => matched
[perdir /Users/Losiowaty/MyApp/] rewrite 'api/poeci' -> 'public/api/poeci'
[perdir /Users/Losiowaty/MyApp/] add per-dir prefix: public/api/poeci -> /Users/Losiowaty/MyApp/public/api/poeci
[perdir /Users/Losiowaty/MyApp/] strip document_root prefix: /Users/Losiowaty/MyApp/public/api/poeci -> /MyApp/public/api/poeci
[perdir /Users/Losiowaty/MyApp/] internal redirect with /MyApp/public/api/poeci [INTERNAL REDIRECT]
[perdir /Users/Losiowaty/MyApp/public/] add path info postfix: /Users/Losiowaty/MyApp/public/api -> /Users/Losiowaty/MyApp/public/api/poeci
[perdir /Users/Losiowaty/MyApp/public/] strip per-dir prefix: /Users/Losiowaty/MyApp/public/api/poeci -> api/poeci
[perdir /Users/Losiowaty/MyApp/public/] applying pattern '^(.*)$' to uri 'api/poeci'
[perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api' pattern='!-d' => matched
[perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api' pattern='!-f' => matched
[perdir /Users/Losiowaty/MyApp/public/] rewrite 'api/poeci' -> 'api.php?_url=/api/poeci'
split uri=api.php?_url=/api/poeci -> uri=api.php, args=_url=/api/poeci
[perdir /Users/Losiowaty/MyApp/public/] add per-dir prefix: api.php -> /Users/Losiowaty/MyApp/public/api.php
[perdir /Users/Losiowaty/MyApp/public/] strip document_root prefix: /Users/Losiowaty/MyApp/public/api.php -> /MyApp/public/api.php
[perdir /Users/Losiowaty/MyApp/public/] internal redirect with /MyApp/public/api.php [INTERNAL REDIRECT]
[perdir /Users/Losiowaty/MyApp/public/] strip per-dir prefix: /Users/Losiowaty/MyApp/public/api.php -> api.php
[perdir /Users/Losiowaty/MyApp/public/] applying pattern '^(.*)$' to uri 'api.php'
[perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api.php' pattern='!-d' => matched
[perdir /Users/Losiowaty/MyApp/public/] RewriteCond: input='/Users/Losiowaty/MyApp/public/api.php' pattern='!-f' => not-matched
[perdir /Users/Losiowaty/MyApp/public/] pass through /Users/Losiowaty/MyApp/public/api.php
Remote log :
[perdir /var/www/MyApp/] add path info postfix: /var/www/MyApp/api -> /var/www/MyApp/api/poeci
[perdir /var/www/MyApp/] strip per-dir prefix: /var/www/MyApp/api/poeci -> api/poeci
[perdir /var/www/MyApp/] applying pattern '^$' to uri 'api/poeci'
[perdir /var/www/MyApp/] add path info postfix: /var/www/MyApp/api -> /var/www/MyApp/api/poeci
[perdir /var/www/MyApp/] strip per-dir prefix: /var/www/MyApp/api/poeci -> api/poeci
[perdir /var/www/MyApp/] applying pattern '(.*)' to uri 'api/poeci'
[perdir /var/www/MyApp/] RewriteCond: input='/MyApp/api/poeci' pattern='!(\\.gif|\\.jpg|\\.png|\\.mp3|\\.ods|\\.csv|\\.xls)$' [NC] => matched
[perdir /var/www/MyApp/] rewrite 'api/poeci' -> 'public/api/poeci'
[perdir /var/www/MyApp/] add per-dir prefix: public/api/poeci -> /var/www/MyApp/public/api/poeci
[perdir /var/www/MyApp/] strip document_root prefix: /var/www/MyApp/public/api/poeci -> /MyApp/public/api/poeci
[perdir /var/www/MyApp/] internal redirect with /MyApp/public/api/poeci [INTERNAL REDIRECT]
[perdir /var/www/MyApp/public/] add path info postfix: /var/www/MyApp/public/api.php -> /var/www/MyApp/public/api.php/poeci
[perdir /var/www/MyApp/public/] strip per-dir prefix: /var/www/MyApp/public/api.php/poeci -> api.php/poeci
[perdir /var/www/MyApp/public/] applying pattern '^(.*)$' to uri 'api.php/poeci'
[perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-d' => matched
[perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-f' => not-matched
[perdir /var/www/MyApp/public/] pass through /var/www/MyApp/public/api.php
[perdir /var/www/MyApp/public/] add path info postfix: /var/www/MyApp/public/api.php -> /var/www/MyApp/public/api.php/poeci
[perdir /var/www/MyApp/public/] strip per-dir prefix: /var/www/MyApp/public/api.php/poeci -> api.php/poeci
[perdir /var/www/MyApp/public/] applying pattern '^(.*)$' to uri 'api.php/poeci'
[perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-d' => matched
[perdir /var/www/MyApp/public/] RewriteCond: input='/var/www/MyApp/public/api.php' pattern='!-f' => not-matched
[perdir /var/www/MyApp/public/] pass through /var/www/MyApp/public/api.php
[perdir /var/www/] strip per-dir prefix: /var/www/poeci -> poeci
[perdir /var/www/] applying pattern '^index\\.php$' to uri 'poeci'
[perdir /var/www/] strip per-dir prefix: /var/www/poeci -> poeci
[perdir /var/www/] applying pattern '.' to uri 'poeci'
[perdir /var/www/] RewriteCond: input='/poeci' pattern='!(redmine|MyApp)' [NC] => matched
[perdir /var/www/] RewriteCond: input='/var/www/poeci' pattern='!-f' => matched
[perdir /var/www/] RewriteCond: input='/var/www/poeci' pattern='!-d' => matched
[perdir /var/www/] rewrite 'poeci' -> '/index.php'
[perdir /var/www/] trying to replace prefix /var/www/ with /
[perdir /var/www/] internal redirect with /index.php [INTERNAL REDIRECT]
The differences begin with the first line with [perdir (...)] ending with /public/. I don't understand why it adds .php and why the !-f rule doesn't match on the remote server.
Local server :
OSX 10.9.3, MAMP 3.0.4, Apache 2.2.26
Remote server :
Debian GNU/Linux 6.0.9, Apache 2.2.16
I wonder whether this is caused by the additional .htaccess file on the remote, or by the difference in Apache version.
I'd appreciate some explanation as to what's going on and any directions on where to look for answers.
Cheers!
This looks like it may be caused by multiviews. In both htaccess files inside MyApp, add this (above your rules, but anywhere is fine):
Options -Multiviews
Note that because api.php exists, a PATH INFO url like: /MyApp/api.php/something will fail the !-f check.

adding index.cfm to url seems to ignore .htaccess

I'm trying to disallow access to certain folders in my webApp, but there seems to be some exception to the use of index.cfm somewhere...
for this example I'm using just the folllowing mod_rewrite rule:
RewriteRule ^(.*)$ index.cfm [QSA,L]
accessing the following urls with results:
/index.cfm //->/index.cfm naturally
/test/test.html //->/index.cfm
/test/ //->/index.cfm
/test/test.cfm //->/index.cfm
/test/index.cfm //->/test/index.cfm
Note that the last request seems to ignore the rewrite rule, how could that happen?
(All files above are not present in the file system with exception to the index.cfm in the root)
EDIT also, the .htaccess file is placed in the root directory
EDIT 2 I added a RewriteLog to see whats going on, There definitely is a difference but I dont see why...
/test/index.html
[rid#15d1048/initial] (2) init rewrite engine with requested uri /test/index.html
[rid#15d1048/initial] (1) pass through /test/index.html
[rid#15d1048/initial] (3) [perdir C:/my/local/dir/] add path info postfix: C:/my/local/dir/test -> C:/my/local/dir/test/index.html
[rid#15d1048/initial] (3) [perdir C:/my/local/dir/] strip per-dir prefix: C:/my/local/dir/test/index.html -> test/index.html
[rid#15d1048/initial] (3) [perdir C:/my/local/dir/] applying pattern '^(.*)$' to uri 'test/index.html'
[rid#15d1048/initial] (2) [perdir C:/my/local/dir/] rewrite 'test/index.html' -> 'index.cfm'
[rid#15d1048/initial] (3) [perdir C:/my/local/dir/] add per-dir prefix: index.cfm -> C:/my/local/dir/index.cfm
[rid#15d1048/initial] (2) [perdir C:/my/local/dir/] strip document_root prefix: C:/my/local/dir/index.cfm -> /index.cfm
[rid#15d1048/initial] (1) [perdir C:/my/local/dir/] internal redirect with /index.cfm [INTERNAL REDIRECT]
[rid#15cb4c0/initial/redir#1] (2) init rewrite engine with requested uri /index.cfm
[rid#15cb4c0/initial/redir#1] (1) pass through /index.cfm
[rid#15cb4c0/initial/redir#1] (3) [perdir C:/my/local/dir/] strip per-dir prefix: C:/my/local/dir/index.cfm -> index.cfm
[rid#15cb4c0/initial/redir#1] (3) [perdir C:/my/local/dir/] applying pattern '^(.*)$' to uri 'index.cfm'
[rid#15cb4c0/initial/redir#1] (2) [perdir C:/my/local/dir/] rewrite 'index.cfm' -> 'index.cfm'
[rid#15cb4c0/initial/redir#1] (3) [perdir C:/my/local/dir/] add per-dir prefix: index.cfm -> C:/my/local/dir/index.cfm
[rid#15cb4c0/initial/redir#1] (1) [perdir C:/my/local/dir/] initial URL equal rewritten URL: C:/my/local/dir/index.cfm [IGNORING REWRITE]
/test/index.cfm
[rid#15ca1a0/initial] (2) init rewrite engine with requested uri /test/index.cfm
[rid#15ca1a0/initial] (1) pass through /test/index.cfm
[rid#15ca1a0/initial] (3) [perdir C:/my/local/dir/] add path info postfix: C:/my/local/dir/test -> C:/my/local/dir/test/index.cfm
[rid#15ca1a0/initial] (3) [perdir C:/my/local/dir/] strip per-dir prefix: C:/my/local/dir/test/index.cfm -> test/index.cfm
[rid#15ca1a0/initial] (3) [perdir C:/my/local/dir/] applying pattern '^(.*)$' to uri 'test/index.cfm'
[rid#15ca1a0/initial] (2) [perdir C:/my/local/dir/] rewrite 'test/index.cfm' -> 'index.cfm'
[rid#15ca1a0/initial] (3) [perdir C:/my/local/dir/] add per-dir prefix: index.cfm -> C:/my/local/dir/index.cfm
[rid#15ca1a0/initial] (2) [perdir C:/my/local/dir/] strip document_root prefix: C:/my/local/dir/index.cfm -> /index.cfm
[rid#15ca1a0/initial] (1) [perdir C:/my/local/dir/] internal redirect with /index.cfm [INTERNAL REDIRECT]
Not the perfect answer i was looking for but this is what I did to get the same result:
In the .htaccess I add the following line to forward any files not processed by railo:
RewriteCond %{REQUEST_URI} ^/(my|forbidden|folders)
RewriteRule ^(.*)$ /index.cfm/some/page [L]
In the application.cfc I add the following line to forward the files processed by railo:
<cfif Find(listFirst(arguments.targetPage, "/"), "my,forbidden,folders")>
<cfset GetPageContext().Forward("/index.cfm/some/page")>
</cfif>
This way I can show another page whilst not changing the requested url.
I was hoping for a solution just in the .htaccess but it seems because of a bug in the resin / apache connection this cannot work yet.

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)!)

Any idea why this mod_rewrite rule isn't matching, I think it should be

My ubuntu localhost mod_rewrite is acting funky. I'm trying to rewrite the url:
mydomain.com/random/50/post-title-here/
to:
mydomain.com/random.php?id=50
using the rewrite rule:
Options -MultiViews
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^random/([0-9]+)$ random.php?id=$1
I can't for the life of me see how that simple rule could be matched wrong, but it just isn't working as you can see from the rewrite log that I've cleaned up and presented here.
RewriteCond: input='www.mydomain.com' pattern='^mydomain\.com$' [NC] => not-matched
127.0.0.1 - - [11/Oct/2011:11:12:44 --0500] [www.mydomain.com/sid#b7a4fc90][rid#b7c0f340/initial/redir#1] (1) [perdir /var/www/] pass through /var/www/rewrite.php
add path info postfix: /var/www/random -> /var/www/random/7960/we-serve-up-phat-beets-at-my-house/
strip per-dir prefix: /var/www/random/7960/we-serve-up-phat-beets-at-my-house/ -> random/7960/we-serve-up-phat-beets-at-my-house/
applying pattern '^random/([0-9]+)$' to uri 'random/7960/we-serve-up-phat-beets-at-my-house/'
add path info postfix: /var/www/random -> /var/www/random/7960/we-serve-up-phat-beets-at-my-house/
strip per-dir prefix: /var/www/random/7960/we-serve-up-phat-beets-at-my-house/ -> random/7960/we-serve-up-phat-beets-at-my-house/
applying pattern '^link([^/]*).html$' to uri 'random/7960/we-serve-up-phat-beets-at-my-house/'
add path info postfix: /var/www/random -> /var/www/random/7960/we-serve-up-phat-beets-at-my-house/
strip per-dir prefix: /var/www/random/7960/we-serve-up-phat-beets-at-my-house/ -> random/7960/we-serve-up-phat-beets-at-my-house/
applying pattern '^(.*)$' to uri 'random/7960/we-serve-up-phat-beets-at-my-house/'
RewriteCond: input='mydomain.com' pattern='^mydomain\.com$' [NC] => matched
rewrite 'random/7960/we-serve-up-phat-beets-at-my-house/' -> 'http://www.mydomain.com/random/7960/we-serve-up-phat-beets-at-my-house/'
explicitly forcing redirect with http://www.mydomain.com/random/7960/we-serve-up-phat-beets-at-my-house/
trying to replace prefix /var/www/ with /
escaping http://www.mydomain.com/random/7960/we-serve-up-phat-beets-at-my-house/ for redirect
redirect to http://www.mydomain.com/random/7960/we-serve-up-phat-beets-at-my-house/ [REDIRECT/301]
add path info postfix: /var/www/random -> /var/www/random/7960/we-serve-up-phat-beets-at-my-house/
strip per-dir prefix: /var/www/random/7960/we-serve-up-phat-beets-at-my-house/ -> random/7960/we-serve-up-phat-beets-at-my-house/
applying pattern '^random/([0-9]+)$' to uri 'random/7960/we-serve-up-phat-beets-at-my-house/'
add path info postfix: /var/www/random -> /var/www/random/7960/we-serve-up-phat-beets-at-my-house/
strip per-dir prefix: /var/www/random/7960/we-serve-up-phat-beets-at-my-house/ -> random/7960/we-serve-up-phat-beets-at-my-house/
applying pattern '^link([^/]*).html$' to uri 'random/7960/we-serve-up-phat-beets-at-my-house/'
add path info postfix: /var/www/random -> /var/www/random/7960/we-serve-up-phat-beets-at-my-house/
strip per-dir prefix: /var/www/random/7960/we-serve-up-phat-beets-at-my-house/ -> random/7960/we-serve-up-phat-beets-at-my-house/
applying pattern '^(.*)$' to uri 'random/7960/we-serve-up-phat-beets-at-my-house/'
RewriteCond: input='www.mydomain.com' pattern='^mydomain\.com$' [NC] => not-matched
pass through /var/www/random
Any ideas stack?
The $ meta-character means "assert end of subject", so your URL will not match unless it doesn't have anything else after the digits.