Page 1 of 1

RegEx Match Help

Posted: Mon May 26, 2008 5:40 pm
by aliasxneo
I'm using some rewrite rules that look like this:

Code: Select all

RewriteEngine on
RewriteRule ^([A-Za-z].*)/ index.php?query=$1 [nc]
RewriteRule ^([A-Za-z].*)/\?(.*) index.php?query=$1&get=$2 [nc]
Here's what should happen:

Code: Select all

http://www.mysite.com/test/test1/  produces:
http://www.mysite.com/index.php?query=test/test1
 
http://www.mysite.com/test/test1/?somevar=value  produces:
http://www.mysite.com/index.php?query=t ... =somevalue
The first url rewriting works fine. It's the second one that won't work. I've went and simulated what the url would look like and tested the regex I have for the second rule against it and it worked perfectly (returned test/test1 and somevar=somevalue). I've no idea why it won't work here though. Does anyone have any alternative RegEx or can someone explain what I might be doing wrong? Thanks.

Re: RegEx Match Help

Posted: Mon May 26, 2008 6:17 pm
by whiterabbit
I think if you switch the order and add a [L], that should do it. Otherwise, I can help you with a new reg-ex.

Code: Select all

 
RewriteEngine on
RewriteRule ^([A-Za-z].*)/\?(.*) index.php?query=$1&get=$2 [nc, L]
RewriteRule ^([A-Za-z].*)$/ index.php?query=$1 [nc]
 

Re: RegEx Match Help

Posted: Mon May 26, 2008 6:49 pm
by aliasxneo
whiterabbit wrote:I think if you switch the order and add a [L], that should do it. Otherwise, I can help you with a new reg-ex.

Code: Select all

 
RewriteEngine on
RewriteRule ^([A-Za-z].*)/\?(.*) index.php?query=$1&get=$2 [nc, L]
RewriteRule ^([A-Za-z].*)$/ index.php?query=$1 [nc]
 
What's the L do? I switched the order and nothing happened. Then I added the L and got an internal server error.

Re: RegEx Match Help

Posted: Tue May 27, 2008 1:15 am
by GeertDD
aliasxneo wrote:What's the L do? I switched the order and nothing happened. Then I added the L and got an internal server error.
The L flag stands for "last rule".
See: http://rewrite.drbacchus.com/rewritewiki/Flags_2fL

You are getting an internal server error because of the space inside [NC, L]. Change it to [NC,L].