Forum Moderators: coopster & phranque

Message Too Old, No Replies

Another regular expression problem

         

designaweb

12:42 pm on Dec 8, 2002 (gmt 0)

10+ Year Member



RewriteEngine on

RewriteCond %{REQUEST_URI} \/{1}
RewriteRule ^(.*)/ cheats.php?action=showtitles&platform=$1 [L]

RewriteCond %{REQUEST_URI} \/{2}
RewriteRule ^([^\/]*)\/(.*)/ cheats.php?action=showtitles&platform=$1&letter=$2 [L]

If the {REQUEST_URI} contains 1 "/" it should run the first rule, if it contains 2 "/" then it should run the 2nd...

The thing is, it doesnt :(

What's wrong here?

jdMorgan

5:02 pm on Dec 8, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



designaweb,

The basic problem is that there is no end anchor on your patterns. Without an end anchor, everything in the pattern you specify can be followed by anything (including another slash) and still match - Not having an end anchor is the same as specifying ".*" on the end.

^[^/]+/[^/]+$ could be used to find anything/anything
^[^/]+/[^/]+/[^/]+$ could similarly be used to find anything/anything/anything.
In both cases, there must be something (anything other than a slash) before and after the slashes to match the pattern. Note that within square brackets "^" means "not". This is different from it's usual job as a start anchor.

HTH,
Jim

designaweb

5:48 pm on Dec 8, 2002 (gmt 0)

10+ Year Member



Thanx a lot, I have spent all day searching on regex & mod_rewrite. I kinda got a solution already, but your explanation helps me even more.

This forum is an extremely friendly & usefull place, that I would recommend to anyone. I know, since I am a member at many boards, even an admin/mod at some of them...

jdMorgan

7:03 pm on Dec 8, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



designaweb,

You're welcome. It is a great board, isn't it? :)

Jim