mod_rewrite niepotrzebnie robi redirect zamiast internal

0

Mam dziwny problem z mod_rewrite: mianowicie zamiast po cichu pod maską przekazać adres jako parametr, daje jakby "podwójnie". Raz przekazuje dobrze, a następnym razem dodaje redirect 301 na zasób niepotrzebny.

Oto newralgiczny kod:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

#Passthrough for EXISTING files
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]

RewriteCond %{IS_SUBREQ} false
RewriteCond %{REQUEST_FILENAME} /gallery/
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^gallery/(.*)$ gallery.php?dir=$1 [L]

</IfModule>

w założeniu powinno toto każdy request do /gallery/cokolwiek/cokolwiek... przekazać do galery.php w parametrze dir, ale robić to "po cichu"
w praktycze robi tak:

  1. request do /gallery/test1
  2. 301 do /gallery/test1?dir=test1

w rewrite log nic nie mogę zakumać:

127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (3) [perdir /home/johnny/public_html/tp/] strip per-dir prefix: /home/johnny/public_html/tp/gallery/test2 -> gallery/test2
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (3) [perdir /home/johnny/public_html/tp/] applying pattern '.*' to uri 'gallery/test2'
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (4) [perdir /home/johnny/public_html/tp/] RewriteCond: input='/home/johnny/public_html/tp/gallery/test2' pattern='-f' => not-matched
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (3) [perdir /home/johnny/public_html/tp/] strip per-dir prefix: /home/johnny/public_html/tp/gallery/test2 -> gallery/test2
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (3) [perdir /home/johnny/public_html/tp/] applying pattern '^thumbs/(.*)$' to uri 'gallery/test2'
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (3) [perdir /home/johnny/public_html/tp/] strip per-dir prefix: /home/johnny/public_html/tp/gallery/test2 -> gallery/test2
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (3) [perdir /home/johnny/public_html/tp/] applying pattern '^gallery/(.*)$' to uri 'gallery/test2'
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (4) [perdir /home/johnny/public_html/tp/] RewriteCond: input='false' pattern='false' => matched
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (4) [perdir /home/johnny/public_html/tp/] RewriteCond: input='/home/johnny/public_html/tp/gallery/test2' pattern='/gallery/' => matched
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (4) [perdir /home/johnny/public_html/tp/] RewriteCond: input='/home/johnny/public_html/tp/gallery/test2' pattern='-d' => matched
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (2) [perdir /home/johnny/public_html/tp/] rewrite 'gallery/test2' -> 'gallery.php?dir=test2'
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (3) split uri=gallery.php?dir=test2 -> uri=gallery.php, args=dir=test2
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (3) [perdir /home/johnny/public_html/tp/] add per-dir prefix: gallery.php -> /home/johnny/public_html/tp/gallery.php
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (2) [perdir /home/johnny/public_html/tp/] trying to replace prefix /home/johnny/public_html/tp/ with /
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (5) strip matching prefix: /home/johnny/public_html/tp/gallery.php -> gallery.php
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (4) add subst prefix: gallery.php -> /gallery.php
127.0.0.1 - - [16/Jul/2014:23:39:34 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b289d0/initial] (1) [perdir /home/johnny/public_html/tp/] internal redirect with /gallery.php [INTERNAL REDIRECT]
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (3) [perdir /home/johnny/public_html/tp/] strip per-dir prefix: /home/johnny/public_html/tp/gallery/test2/ -> gallery/test2/
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (3) [perdir /home/johnny/public_html/tp/] applying pattern '.*' to uri 'gallery/test2/'
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (4) [perdir /home/johnny/public_html/tp/] RewriteCond: input='/home/johnny/public_html/tp/gallery/test2/' pattern='-f' => not-matched
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (3) [perdir /home/johnny/public_html/tp/] strip per-dir prefix: /home/johnny/public_html/tp/gallery/test2/ -> gallery/test2/
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (3) [perdir /home/johnny/public_html/tp/] applying pattern '^thumbs/(.*)$' to uri 'gallery/test2/'
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (3) [perdir /home/johnny/public_html/tp/] strip per-dir prefix: /home/johnny/public_html/tp/gallery/test2/ -> gallery/test2/
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (3) [perdir /home/johnny/public_html/tp/] applying pattern '^gallery/(.*)$' to uri 'gallery/test2/'
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (4) [perdir /home/johnny/public_html/tp/] RewriteCond: input='false' pattern='false' => matched
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (4) [perdir /home/johnny/public_html/tp/] RewriteCond: input='/home/johnny/public_html/tp/gallery/test2/' pattern='/gallery/' => matched
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (4) [perdir /home/johnny/public_html/tp/] RewriteCond: input='/home/johnny/public_html/tp/gallery/test2/' pattern='-d' => matched
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (2) [perdir /home/johnny/public_html/tp/] rewrite 'gallery/test2/' -> 'gallery.php?dir=test2/'
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (3) split uri=gallery.php?dir=test2/ -> uri=gallery.php, args=dir=test2/
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (3) [perdir /home/johnny/public_html/tp/] add per-dir prefix: gallery.php -> /home/johnny/public_html/tp/gallery.php
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (2) [perdir /home/johnny/public_html/tp/] trying to replace prefix /home/johnny/public_html/tp/ with /
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (5) strip matching prefix: /home/johnny/public_html/tp/gallery.php -> gallery.php
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (4) add subst prefix: gallery.php -> /gallery.php
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a9d8/initial] (1) [perdir /home/johnny/public_html/tp/] internal redirect with /gallery.php [INTERNAL REDIRECT]
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a1a8/initial/redir#1] (3) [perdir /home/johnny/public_html/tp/] strip per-dir prefix: /home/johnny/public_html/tp/gallery.php -> gallery.php
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a1a8/initial/redir#1] (3) [perdir /home/johnny/public_html/tp/] applying pattern '.*' to uri 'gallery.php'
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a1a8/initial/redir#1] (4) [perdir /home/johnny/public_html/tp/] RewriteCond: input='/home/johnny/public_html/tp/gallery.php' pattern='-f' => matched
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a5b2a1a8/initial/redir#1] (1) [perdir /home/johnny/public_html/tp/] pass through /home/johnny/public_html/tp/gallery.php
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a4a48850/initial] (3) [perdir /home/johnny/public_html/tp/] strip per-dir prefix: /home/johnny/public_html/tp/js/templates/upload.html -> js/templates/upload.html
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a4d512f8/initial] (3) [perdir /home/johnny/public_html/tp/] strip per-dir prefix: /home/johnny/public_html/tp/js/templates/download.html -> js/templates/download.html
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a4a48850/initial] (3) [perdir /home/johnny/public_html/tp/] applying pattern '.*' to uri 'js/templates/upload.html'
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a4d512f8/initial] (3) [perdir /home/johnny/public_html/tp/] applying pattern '.*' to uri 'js/templates/download.html'
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a4a48850/initial] (4) [perdir /home/johnny/public_html/tp/] RewriteCond: input='/home/johnny/public_html/tp/js/templates/upload.html' pattern='-f' => matched
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a4d512f8/initial] (4) [perdir /home/johnny/public_html/tp/] RewriteCond: input='/home/johnny/public_html/tp/js/templates/download.html' pattern='-f' => matched
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a4a48850/initial] (1) [perdir /home/johnny/public_html/tp/] pass through /home/johnny/public_html/tp/js/templates/upload.html
127.0.0.1 - - [16/Jul/2014:23:39:35 +0200] [testprojekt.local/sid#a0f1b38][rid#a4d512f8/initial] (1) [perdir /home/johnny/public_html/tp/] pass through /home/johnny/public_html/tp/js/templates/download.html
0

Ciekawostka: wchodząc w gallery/test3/ działa OK. wchodząc w gallery/test3 robi 301 do gallery/test3/?dir=test3
OCB?

Edit: OK, rozwiązanie na szybko: jeśli ze / na końcu działa, dodać / na końcu, ale przed właściwą regułą.

RewriteCond %{REQUEST_URI} !(/$|\.|^$) 
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L

1 użytkowników online, w tym zalogowanych: 0, gości: 1