On Thu, 24 Jul 2008, Tom Penney wrote:

>> On Wed, 23 Jul 2008, Steve Cayford wrote:
>>> In perl regexes you can use ".*?" instead of ".*" to make it a non-greedy
>>> match. Does that work?
>
> Yes! This works great. I also added the * as Mike suggested to allow
> multiple trailing slashes
> RewriteRule ^(.*?)/*?$ ${txtmap:$1} [L]

That allows for strings that begin with "/" which was expressly disallowed 
in your previous pattern.  I also see that as a little ambiguous in that 
you are using "*?" on both sides of the slash which makes it unclear where 
the slashes should be absorbed.  To make it a little clearer, I would drop 
the second question mark like so:

RewriteRule ^(.*?)/*$ ${txtmap:$1} [L]

Then the second asterisk is clearly "greedy" and it absorbs all the 
slashes.


> Mike's rules below do also work but I'm not sure I understand how they 
> differ from the one above, $1 does not include the trailing slash, and 
> all the listed examples match.

The pattern above:

^(.*?)/*?$

My pattern:

^(([^/]+?/)*[^/]+)/*$

There are three differences:  Mine will not match a line that begins with 
a slash "/" but yours will match such a line.  Mine requires that at least 
one non-slash character be present but yours does not have that 
requirement.  Mine clearly drops the final slashes (the "ambiguity" issue 
I mentioned above that is handled by dropping the second question mark).

I was just basing mine on what you had earlier.

Mike


> The URL which the visitor typed does not change in any case. I think I 
> would have to redirect if I wanted the the trailing slash to be dropped 
> from what the user sees in the address. But everything works :-). Thanks 
> for your help!
>
>
> On Wed, Jul 23, 2008 at 6:51 PM, Mike Miller <mbmiller at taxa.epi.umn.edu> wrote:
>>  I think maybe this is what you want to handle all cases:
>>
>> RewriteRule ^(([^/]+?/)*[^/]+)/?$ ${txtmap:$1} [L]
>>
>> itmatchesthis
>> andthis/
>> and/it/matches/this
>> and/it/matches/this/
>>
>> ...and the trailing slash is dropped such that $1 never has a trailing
>> slash.  By the way, this might be just as good:
>>
>> RewriteRule ^(([^/]+?/)*[^/]+)/*$ ${txtmap:$1} [L]
>>
>> I replaced a question mark with an asterisk to allow any number of trailing
>> slashes, all of which are not held in $1.
>>
>> I don't know if any of this works for you though.
>>
>> Mike
>>
>
>
>
> --
> Tom Penney
> 612-920-3562
>