add path postfix info problem

Oh, the strange things mod_rewrite does!

add path postfix info problem

Postby gpazi » Thu Feb 21, 2008 6:24 am

I accidentally posted this at the wrong forum.
Can't find how to move it to the right forum. Sorry about that.


I am trying to rewrite
http://localtt/israel/herzliya/photos/89 ==>
http://localtt/israel/herzliya/photos.php/89 ==>
http://localtt/photos.php?photo=89&loc1 ... 2=herzliya


Here's my .htaccess (I must use .htaccess) at the top directory:
# Protect files and directories from prying eyes.
<FilesMatch "\.(xml|inc)$">
Order deny,allow
Deny from all
</FilesMatch>

Options +FollowSymlinks -MultiViews
PHP_FLAG output_buffering on
FileETag none

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 300 seconds"
ExpiresByType text/html "access plus 1 day"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
</IfModule>

<IfModule mod_rewrite.c>

RewriteEngine On

# Ignore all real files and directories after this rule.
RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L]

RewriteRule ^(.*)photos([^.].*)?$ $1photos.php$2 [NC,QSA]

# locations url and single entry
RewriteRule ^([a-z+_,-]+)/?([a-z+_,-]*)/?([a-z+_,-]*)/([a-z]+)s.php/([0-9]+)/?(\?.*)?/?$ $5s.php?$4=$5&loc1=$1&loc2=$2&loc3=$3&$6 [NC,QSA,L]


</IfModule>



after the RewriteRule (2) is matched, and rewrite, I get
add path info postfix: D:/eclipsews/trunk/tt/israel/herzliya/photos.php/89 -> D:/eclipsews/trunk/tt/israel/herzliya/photos.php/89/herzliya/photos/89



Here's my log:

127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (3) [per-dir D:/eclipsews/trunk/tt/] add path info postfix: D:/eclipsews/trunk/tt/israel -> D:/eclipsews/trunk/tt/israel/herzliya/photos/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (3) [per-dir D:/eclipsews/trunk/tt/] strip per-dir prefix: D:/eclipsews/trunk/tt/israel/herzliya/photos/89 -> israel/herzliya/photos/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (3) [per-dir D:/eclipsews/trunk/tt/] applying pattern '.*' to uri 'israel/herzliya/photos/89'
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (4) RewriteCond: input='D:/eclipsews/trunk/tt/israel' pattern='-f' => not-matched
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (4) RewriteCond: input='D:/eclipsews/trunk/tt/israel' pattern='-d' => not-matched
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (3) [per-dir D:/eclipsews/trunk/tt/] add path info postfix: D:/eclipsews/trunk/tt/israel -> D:/eclipsews/trunk/tt/israel/herzliya/photos/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (3) [per-dir D:/eclipsews/trunk/tt/] strip per-dir prefix: D:/eclipsews/trunk/tt/israel/herzliya/photos/89 -> israel/herzliya/photos/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (3) [per-dir D:/eclipsews/trunk/tt/] applying pattern '^(.*)photos([^.].*)?$' to uri 'israel/herzliya/photos/89'
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (2) [per-dir D:/eclipsews/trunk/tt/] rewrite israel/herzliya/photos/89 -> israel/herzliya/photos.php/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (3) [per-dir D:/eclipsews/trunk/tt/] add per-dir prefix: israel/herzliya/photos.php/89 -> D:/eclipsews/trunk/tt/israel/herzliya/photos.php/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (3) [per-dir D:/eclipsews/trunk/tt/] add path info postfix: D:/eclipsews/trunk/tt/israel/herzliya/photos.php/89 -> D:/eclipsews/trunk/tt/israel/herzliya/photos.php/89/herzliya/photos/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (3) [per-dir D:/eclipsews/trunk/tt/] strip per-dir prefix: D:/eclipsews/trunk/tt/israel/herzliya/photos.php/89/herzliya/photos/89 -> israel/herzliya/photos.php/89/herzliya/photos/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (3) [per-dir D:/eclipsews/trunk/tt/] applying pattern '^([a-z+_,-]+)/?([a-z+_,-]*)/?([a-z+_,-]*)/([a-z]+)s.php/([0-9]+)/?(\?.*)?/?$' to uri 'israel/herzliya/photos.php/89/herzliya/photos/89'
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (2) [per-dir D:/eclipsews/trunk/tt/] strip document_root prefix: D:/eclipsews/trunk/tt/israel/herzliya/photos.php/89 -> /israel/herzliya/photos.php/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#713918/initial] (1) [per-dir D:/eclipsews/trunk/tt/] internal redirect with /israel/herzliya/photos.php/89 [INTERNAL REDIRECT]
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (3) [per-dir D:/eclipsews/trunk/tt/] add path info postfix: D:/eclipsews/trunk/tt/israel -> D:/eclipsews/trunk/tt/israel/herzliya/photos.php/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (3) [per-dir D:/eclipsews/trunk/tt/] strip per-dir prefix: D:/eclipsews/trunk/tt/israel/herzliya/photos.php/89 -> israel/herzliya/photos.php/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (3) [per-dir D:/eclipsews/trunk/tt/] applying pattern '.*' to uri 'israel/herzliya/photos.php/89'
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (4) RewriteCond: input='D:/eclipsews/trunk/tt/israel' pattern='-f' => not-matched
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (4) RewriteCond: input='D:/eclipsews/trunk/tt/israel' pattern='-d' => not-matched
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (3) [per-dir D:/eclipsews/trunk/tt/] add path info postfix: D:/eclipsews/trunk/tt/israel -> D:/eclipsews/trunk/tt/israel/herzliya/photos.php/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (3) [per-dir D:/eclipsews/trunk/tt/] strip per-dir prefix: D:/eclipsews/trunk/tt/israel/herzliya/photos.php/89 -> israel/herzliya/photos.php/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (3) [per-dir D:/eclipsews/trunk/tt/] applying pattern '^(.*)photos([^.].*)?$' to uri 'israel/herzliya/photos.php/89'
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (3) [per-dir D:/eclipsews/trunk/tt/] add path info postfix: D:/eclipsews/trunk/tt/israel -> D:/eclipsews/trunk/tt/israel/herzliya/photos.php/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (3) [per-dir D:/eclipsews/trunk/tt/] strip per-dir prefix: D:/eclipsews/trunk/tt/israel/herzliya/photos.php/89 -> israel/herzliya/photos.php/89
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (3) [per-dir D:/eclipsews/trunk/tt/] applying pattern '^([a-z+_,-]+)/?([a-z+_,-]*)/?([a-z+_,-]*)/([a-z]+)s.php/([0-9]+)/?(\?.*)?/?$' to uri 'israel/herzliya/photos.php/89'
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (2) [per-dir D:/eclipsews/trunk/tt/] rewrite israel/herzliya/photos.php/89 -> 89s.php?photo=89&loc1=israel&loc2=herzliya&loc3=&
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (3) split uri=89s.php?photo=89&loc1=israel&loc2=herzliya&loc3=& -> uri=89s.php, args=photo=89&loc1=israel&loc2=herzliya&loc3=&
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (3) [per-dir D:/eclipsews/trunk/tt/] add per-dir prefix: 89s.php -> D:/eclipsews/trunk/tt/89s.php
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (2) [per-dir D:/eclipsews/trunk/tt/] strip document_root prefix: D:/eclipsews/trunk/tt/89s.php -> /89s.php
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (1) [per-dir D:/eclipsews/trunk/tt/] internal redirect with /89s.php [INTERNAL REDIRECT]
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71f220/initial/redir#2] (3) [per-dir D:/eclipsews/trunk/tt/] strip per-dir prefix: D:/eclipsews/trunk/tt/89s.php -> 89s.php
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71f220/initial/redir#2] (3) [per-dir D:/eclipsews/trunk/tt/] applying pattern '.*' to uri '89s.php'
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71f220/initial/redir#2] (4) RewriteCond: input='D:/eclipsews/trunk/tt/89s.php' pattern='-f' => not-matched
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71f220/initial/redir#2] (4) RewriteCond: input='D:/eclipsews/trunk/tt/89s.php' pattern='-d' => not-matched
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71f220/initial/redir#2] (3) [per-dir D:/eclipsews/trunk/tt/] strip per-dir prefix: D:/eclipsews/trunk/tt/89s.php -> 89s.php
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71f220/initial/redir#2] (3) [per-dir D:/eclipsews/trunk/tt/] applying pattern '^(.*)photos([^.].*)?$' to uri '89s.php'
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71f220/initial/redir#2] (3) [per-dir D:/eclipsews/trunk/tt/] strip per-dir prefix: D:/eclipsews/trunk/tt/89s.php -> 89s.php
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71f220/initial/redir#2] (3) [per-dir D:/eclipsews/trunk/tt/] applying pattern '^([a-z+_,-]+)/?([a-z+_,-]*)/?([a-z+_,-]*)/([a-z]+)s.php/([0-9]+)/?(\?.*)?/?$' to uri '89s.php'
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71f220/initial/redir#2] (1) [per-dir D:/eclipsews/trunk/tt/] pass through D:/eclipsews/trunk/tt/89s.php


If I remove the last rule, the postfix info is not added, but I need the last rule as well.
Using 'next', i.e. restarting the parsing is not acceptable as this is actually a small part of a very long original set of rules
gpazi
 
Posts: 8
Joined: Mon Sep 17, 2007 5:02 am

Postby richardk » Thu Feb 21, 2008 11:27 am

Try adding the L flag
Code: Select all
<IfModule mod_rewrite.c>
  RewriteEngine On

  # Ignore all real files and directories after this rule.
  RewriteCond %{SCRIPT_FILENAME} -f [OR]
  RewriteCond %{SCRIPT_FILENAME} -d
  RewriteRule .* - [L]

  RewriteRule ^(.+/)photos(/[0-9]+)/?$ /$1photos.php$2 [NC,QSA,L]

  # locations url and single entry
  RewriteRule ^([a-z+_,-]+)/?([a-z+_,-]*)/?([a-z+_,-]*)/([a-z]+)s.php/([0-9]+)/?$ $5s.php?$4=$5&loc1=$1&loc2=$2&loc3=$3&$6 [NC,QSA,L]
</IfModule>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby gpazi » Thu Feb 21, 2008 4:27 pm

Unfortunately I can't.
I want the other rules to apply, and as these rules are only a small subset of my rules, restarting the parsing is not an option.
gpazi
 
Posts: 8
Joined: Mon Sep 17, 2007 5:02 am

Postby richardk » Sat Feb 23, 2008 5:51 pm

Looking closer at the RewriteLog i don't really see the problem, it rewrites to 89s.php in the end
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (3) [per-dir D:/eclipsews/trunk/tt/] applying pattern '^([a-z+_,-]+)/?([a-z+_,-]*)/?([a-z+_,-]*)/([a-z]+)s.php/([0-9]+)/?(\?.*)?/?$' to uri 'israel/herzliya/photos.php/89'
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (2) [per-dir D:/eclipsews/trunk/tt/] rewrite israel/herzliya/photos.php/89 -> 89s.php?photo=89&loc1=israel&loc2=herzliya&loc3=&
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (3) split uri=89s.php?photo=89&loc1=israel&loc2=herzliya&loc3=& -> uri=89s.php, args=photo=89&loc1=israel&loc2=herzliya&loc3=&
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (3) [per-dir D:/eclipsews/trunk/tt/] add per-dir prefix: 89s.php -> D:/eclipsews/trunk/tt/89s.php
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (2) [per-dir D:/eclipsews/trunk/tt/] strip document_root prefix: D:/eclipsews/trunk/tt/89s.php -> /89s.php
127.0.0.1 - - [21/Feb/2008:15:56:18 +0200] [localtt/sid#7014f8][rid#71dcf0/initial/redir#1] (1) [per-dir D:/eclipsews/trunk/tt/] internal redirect with /89s.php [INTERNAL REDIRECT]

Do you have a file called /israel.php?

You could do both steps it in one rule instead
Code: Select all
<IfModule mod_rewrite.c>
  RewriteEngine On

  # Ignore all real files and directories after this rule.
  RewriteCond %{SCRIPT_FILENAME} -f [OR]
  RewriteCond %{SCRIPT_FILENAME} -d
  RewriteRule .* - [L]

  RewriteRule ^([a-z+_,-]+)(?:/([a-z+_,-]+)(?:/([a-z+_,-]+))?)?/(photos)/([0-9]+)/?$ /$5s.php?$4=$5&loc1=$1&loc2=$2&loc3=$3 [NC,QSA,L]
</IfModule>

You can replace "photos" with "photos|trees|anything|else" to make it match /a/b/c/trees/123 as well.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby gpazi » Sat Feb 23, 2008 11:48 pm

Hi Richard,
I don't want it to rewrite to 89s.php.
I am trying to rewrite
http://localtt/israel/herzliya/photos/89 ==>
http://localtt/israel/herzliya/photos.php/89 ==>
http://localtt/photos.php?photo=89&loc1 ... 2=herzliya

I cannot unify the rules. These rules are just a small subset of my .htaccess

I just wanted to know why this postfix is added. How come there's a different behavior when it's the last/non-last rule, and how can I avoid this postfix

Thanks
Guy
gpazi
 
Posts: 8
Joined: Mon Sep 17, 2007 5:02 am

Postby richardk » Sun Feb 24, 2008 9:53 am

I cannot unify the rules. These rules are just a small subset of my .htaccess

Post it all then.

I don't want it to rewrite to 89s.php.

Doh, i missed that. Well 89 is the fifth part ($5), you need it to replace $5s.php with $4s.php or you need to put /89 before photo.php.

I just wanted to know why this postfix is added. How come there's a different behavior when it's the last/non-last rule, and how can I avoid this postfix

I'm don't know. It has something to do with it being a file with /something after it (PATH_INFO).
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 2 guests

cron