add path info postfix problem

Oh, the strange things mod_rewrite does!

add path info postfix problem

Postby xrado » Wed May 06, 2009 3:22 am

request: http://somepage.it/product/7
rewrites to http://somepage.it/product/7/7

any idea why?

my mod_rewrite
Code: Select all
RewriteCond %{HTTP_HOST} somepage.it
RewriteCond %{REQUEST_URI} !^/it
RewriteCond %{REQUEST_URI} !^/(images|css|js|image)
RewriteRule ^(.*)$ /it/$1

# Rewrite URLs of the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]


log
Code: Select all
[somepage.it/sid#8151808][rid#8322868/initial] (2) init rewrite engine with requested uri /product/7
[somepage.it/sid#8151808][rid#8322868/initial] (1) pass through /product/7
[somepage.it/sid#8151808][rid#8322868/initial] (3) [perdir /home/www/pages/somepage2/public/] add path info postfix: /home/www/pages/somepage2/public/product -> /home/www/pages/somepage2/public/product/7
[somepage.it/sid#8151808][rid#8322868/initial] (3) [perdir /home/www/pages/somepage2/public/] strip per-dir prefix: /home/www/pages/somepage2/public/product/7 -> product/7
[somepage.it/sid#8151808][rid#8322868/initial] (3) [perdir /home/www/pages/somepage2/public/] applying pattern '^(.*)$' to uri 'product/7'
[somepage.it/sid#8151808][rid#8322868/initial] (4) [perdir /home/www/pages/somepage2/public/] RewriteCond: input='somepage.it' pattern='somepage.it' => matched
[somepage.it/sid#8151808][rid#8322868/initial] (4) [perdir /home/www/pages/somepage2/public/] RewriteCond: input='/product/7' pattern='!^/it' => matched
[somepage.it/sid#8151808][rid#8322868/initial] (4) [perdir /home/www/pages/somepage2/public/] RewriteCond: input='/product/7' pattern='!^/(images|css|js|image)' => matched
[somepage.it/sid#8151808][rid#8322868/initial] (2) [perdir /home/www/pages/somepage2/public/] rewrite 'product/7' -> '/it/product/7'
[somepage.it/sid#8151808][rid#8322868/initial] (3) [perdir /home/www/pages/somepage2/public/] add path info postfix: /it/product/7 -> /it/product/7/7
[somepage.it/sid#8151808][rid#8322868/initial] (3) [perdir /home/www/pages/somepage2/public/] applying pattern '^(.*)$' to uri '/it/product/7/7'
[somepage.it/sid#8151808][rid#8322868/initial] (4) [perdir /home/www/pages/somepage2/public/] RewriteCond: input='/it/product/7' pattern='!-f' => matched
[somepage.it/sid#8151808][rid#8322868/initial] (4) [perdir /home/www/pages/somepage2/public/] RewriteCond: input='/it/product/7' pattern='!-d' => matched
[somepage.it/sid#8151808][rid#8322868/initial] (2) [perdir /home/www/pages/somepage2/public/] rewrite '/it/product/7/7' -> 'index.php?q=/it/product/7/7'
[somepage.it/sid#8151808][rid#8322868/initial] (3) split uri=index.php?q=/it/product/7/7 -> uri=index.php, args=q=/it/product/7/7
[somepage.it/sid#8151808][rid#8322868/initial] (3) [perdir /home/www/pages/somepage2/public/] add per-dir prefix: index.php -> /home/www/pages/somepage2/public/index.php
[somepage.it/sid#8151808][rid#8322868/initial] (2) [perdir /home/www/pages/somepage2/public/] strip document_root prefix: /home/www/pages/somepage2/public/index.php -> /index.php
[somepage.it/sid#8151808][rid#8322868/initial] (1) [perdir /home/www/pages/somepage2/public/] internal redirect with /index.php [INTERNAL REDIRECT]
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (2) init rewrite engine with requested uri /index.php
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (1) pass through /index.php
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (3) [perdir /home/www/pages/somepage2/public/] strip per-dir prefix: /home/www/pages/somepage2/public/index.php -> index.php
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (3) [perdir /home/www/pages/somepage2/public/] applying pattern '^(.*)$' to uri 'index.php'
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (4) [perdir /home/www/pages/somepage2/public/] RewriteCond: input='somepage.it' pattern='somepage.it' => matched
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (4) [perdir /home/www/pages/somepage2/public/] RewriteCond: input='/index.php' pattern='!^/it' => matched
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (4) [perdir /home/www/pages/somepage2/public/] RewriteCond: input='/index.php' pattern='!^/(images|css|js|image)' => matched
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (2) [perdir /home/www/pages/somepage2/public/] rewrite 'index.php' -> '/it/index.php'
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (3) [perdir /home/www/pages/somepage2/public/] applying pattern '^(.*)$' to uri '/it/index.php'
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (4) [perdir /home/www/pages/somepage2/public/] RewriteCond: input='/it/index.php' pattern='!-f' => matched
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (4) [perdir /home/www/pages/somepage2/public/] RewriteCond: input='/it/index.php' pattern='!-d' => matched
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (2) [perdir /home/www/pages/somepage2/public/] rewrite '/it/index.php' -> 'index.php?q=/it/index.php'
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (3) split uri=index.php?q=/it/index.php -> uri=index.php, args=q=/it/index.php&q=/it/product/7/7
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (3) [perdir /home/www/pages/somepage2/public/] add per-dir prefix: index.php -> /home/www/pages/somepage2/public/index.php
[somepage.it/sid#8151808][rid#8300d88/initial/redir#1] (1) [perdir /home/www/pages/somepage2/public/] initial URL equal rewritten URL: /home/www/pages/somepage2/public/index.php [IGNORING REWRITE]
xrado
 
Posts: 3
Joined: Wed May 06, 2009 1:53 am

Postby richardk » Wed May 06, 2009 9:13 am

What version of Apache are you using?
Do you have a file called /products.something or a directory called /products?

An explanation and fix (Apache 2.2+ only)
'discardpathinfo|DPI' (discard PATH_INFO)

In per-directory context, the URI each RewriteRule compares against is the concatenation of the current values of the URI and PATH_INFO.

The current URI can be the initial URI as requested by the client, the result of a previous round of mod_rewrite processing, or the result of a prior rule in the current round of mod_rewrite processing.

In contrast, the PATH_INFO that is appended to the URI before each rule reflects only the value of PATH_INFO before this round of mod_rewrite processing. As a consequence, if large portions of the URI are matched and copied into a substitution in multiple RewriteRule directives, without regard for which parts of the URI came from the current PATH_INFO, the final URI may have multiple copies of PATH_INFO appended to it.

Use this flag on any substitution where the PATH_INFO that resulted from the previous mapping of this request to the filesystem is not of interest. This flag permanently forgets the PATH_INFO established before this round of mod_rewrite processing began. PATH_INFO will not be recalculated until the current round of mod_rewrite processing completes. Subsequent rules during this round of processing will see only the direct result of substitutions, without any PATH_INFO appended.

Ie. It thinks /products is the REQUEST_URI, /7 is the PATH_INFO and so it's appending the PATH_INFO to the new URL.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby xrado » Wed May 06, 2009 12:33 pm

I'm running Apache/2.2.10
no there is no file or dir like
xrado
 
Posts: 3
Joined: Wed May 06, 2009 1:53 am

Postby richardk » Wed May 06, 2009 1:25 pm

Try the DPI flag.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?somepage\.it$ [NC]
RewriteCond %{REQUEST_URI} !^/(css|images?|it|js)(/.*)?$ [NC]
RewriteRule ^(.*)$ /it/$1 [DPI]

# Rewrite URLs of the form 'index.php?q=x'.
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby xrado » Wed May 06, 2009 10:42 pm

i get Internal Server Error with DPI

for now i found this solution:
Code: Select all
# .it
RewriteCond %{HTTP_HOST} ^(www\.)?somesite\.it
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?q=/it/$1 [L,QSA]

# .com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
xrado
 
Posts: 3
Joined: Wed May 06, 2009 1:53 am


Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 16 guests

cron