Forum Moderators: phranque

Message Too Old, No Replies

similar structure, different result

         

BlueBlizz

11:31 am on Sep 30, 2009 (gmt 0)

10+ Year Member



I've got a condition and rule in htaccess:

RewriteCond %{REQUEST_URI} !^/hardlopen
RewriteCond %{REQUEST_URI} !^/biking
RewriteCond %{REQUEST_URI} !^/outdoor
RewriteRule ^/?([^A1]*)/$ ${Catmap:$1} [R=301,L,NC]

An url like : [domain.nl...]
give in a logfile:
(3) applying pattern '^/?([^A1]*)/$' to uri 'running/'
(4) RewriteCond: input='/running/' pattern='!^/hardlopen' => matched
(4) RewriteCond: input='/running/' pattern='!^/biking' => matched
(4) RewriteCond: input='/running/' pattern='!^/outdoor=> matched
(5) map lookup OK: map=Catmap[txt] key=running -> val=hardlopen/
(1) escaping [domain.nl...] for redirect
(1) redirect to [domain.nl...] [REDIRECT/301]

so far so good.

chanigng the url to :
An url like : [domain.nl...]
give in logfile:
(3) applying pattern '^/?([^A1]*)/$' to uri 'recreation/'
(3) add path info postfix: /home/epages5/eproot/Shared/WebRoot/recreation -> /home/epages5/eproot/Shared/WebRoot/recreation/

it seems that the patern is not correct for the uri?

Eric

Caterham

12:53 pm on Sep 30, 2009 (gmt 0)

10+ Year Member



Please, don't post just mini-snippets. An other rule is to be be applied. This is correct behavior.

it seems that the patern is not correct for the uri?

It is not r->uri, you're looking at r->filename. That is the physical path to the resource (/home/epages5/eproot/Shared/WebRoot/recreation) which gets r->path_info appended. The latter one is the part not resolving to a folder in your filesystem. See the CGI spec for details. The folder /home/epages5/eproot/Shared/WebRoot/recreation/ does not exist, so the first part (recreation) followed by the last existing folder (/home/epages5/eproot/Shared/WebRoot/) is treated as a file, the rest (/) as path_info.

BlueBlizz

3:16 pm on Sep 30, 2009 (gmt 0)

10+ Year Member



Sorry for the mini-snippet. I'm just familiar with this site/forum for a short time. Sorry again.

/recreation is treated as a file?
Why isn't it treated in the same way as /running ?

Caterham

3:35 pm on Sep 30, 2009 (gmt 0)

10+ Year Member



May be I should add that there's nothing with mini snippets, if they contain all relevant data. ;-) You should see below your last posted line in your log how the per-directory prefix (=directory where you put your .htaccess file or <Directory /the/path/to/some/place> in httpd.conf) would be striped so that you're matching against the expected string 'recreation/'.

/recreation is treated as a file?

Yes, that's the standard how to resolve to physical paths and leave the rest as path_info.

If you would request /foo/bar/other which would be mapped to /home/epages5/eproot/Shared/WebRoot/foo/bar/other and the folder /foo/ does not exist, you'd look against a physical path of /home/epages5/eproot/Shared/WebRoot/foo with path_info /bar/other. foo is treated as a file (whether it exists or not). To give you the chance to match against something with your RewriteRule which looks more like the original request, mod_rewrite adds path_info back to the filename.

Why isn't it treated in the same way as /running ?

The folder exists?

BlueBlizz

3:59 pm on Sep 30, 2009 (gmt 0)

10+ Year Member



both
/home/epages5/eproot/Shared/WebRoot/running
and
/home/epages5/eproot/Shared/WebRoot/recreation
do not exists.

ls: /home/epages5/eproot/Shared/WebRoot/running: No such file or directory
ls: /home/epages5/eproot/Shared/WebRoot/recreation: No such file or directory

these are only intermediate steps.
www.domain.nl/running is rewriten to an url ePages (our e-commerce software) knows. This is done in the last part of htaccess.

Caterham

4:00 pm on Sep 30, 2009 (gmt 0)

10+ Year Member



ls: /home/epages5/eproot/Shared/WebRoot/running: No such file or directory

As you can see, there's no trailing slash (stripped), so it's treated as a file, too.

BTW: You are aware that ^/?([^A1]*)/$ does not (only) mean "not the string A1" but not 'A' (and not 'a' due to your NC flag) and not '1', so it won't match Apple nor Chicago nor recreation, too.

jd01

5:19 pm on Sep 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmmm...

Sorry for jumping in, but ^/?([^A1]*)/$ will not match the path containing /running either because of the /$ at the end, it actually stops processing sooner on recreation than on running.

And, the /? is unnecessary in the .htaccess file, unless there is something I am missing, because the preceding / is not present. In the httpd.conf it would be necessary, but the path matched in the .htaccess will (should) not ever begin with /.

jdMorgan

6:35 pm on Sep 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Perhaps the intent was:

RewriteCond %{REQUEST_URI} !^/hardlopen
RewriteCond %{REQUEST_URI} !^/biking
RewriteCond %{REQUEST_URI} !^/outdoor
RewriteCond %{REQUEST_URI} !/A1
RewriteRule ^(.+)/?$ ${Catmap:$1} [NC,R=301,L]

Jim