Sub-folder redirect not behaving as expected

Discuss practical ways rearrange URLs using mod_rewrite.

Sub-folder redirect not behaving as expected

Postby evolverine » Tue Aug 19, 2008 7:05 am

Hello,

I have two .htaccess files, one in the root folder and one in the folder /test. What I want to do is redirect any request (.*) toward test/some/additional/info/$1, then in the test folder use that additional info somehow.

Now the problem is that when the request gets to the test folder, it gets rewritten into $1/additional/info/$1, instead of the desired $1.

Here is the .htaccess from the root folder:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^localhost$
RewriteRule ^(.*)$ test/some/additional/info/$1 [L,NC]


And here is the .htaccess from the test folder:

RewriteEngine on
RewriteRule ^/?(some/additional/info)/(.*)/?$ $2 [NC,E=someAdditionalInfo:$1]
RewriteRule ^([0-9a-zA-Z_\-~\%\/,]+)$ ?cmd=$1 [L,NC]


When I look at the logs, the server is doing what I want it to here:

127.0.0.1 - - [19/Aug/2008:17:58:49 +0300] [localhost/sid#1801f90][rid#7f95aa8/initial/redir#1] (2) [perdir C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/aziincluj/test/] rewrite 'some/additional/info/dtest/ok/now' -> 'dtest/ok/now' - great!

, and the weird (for me, at least) replacement is done a couple of steps after:

127.0.0.1 - - [19/Aug/2008:17:58:49 +0300] [localhost/sid#1801f90][rid#7f95aa8/initial/redir#1] (3) [perdir C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/aziincluj/test/] add path info postfix: C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/aziincluj/test/dtest/ok/now -> C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/aziincluj/test/dtest/ok/now/additional/info/dtest/ok/now - bad! why is this happening?
evolverine
 
Posts: 2
Joined: Tue Aug 19, 2008 6:46 am

solved!

Postby evolverine » Wed Aug 20, 2008 2:00 am

I just had to add the 'PT' directive: RewriteRule ^/?(some/additional/info)/(.*)/?$ $2 [PT,NC,E=someAdditionalInfo:$1]
evolverine
 
Posts: 2
Joined: Tue Aug 19, 2008 6:46 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 41 guests

cron