Newbie rewrite question

Nov 28, 2010 at 12:37 AM

Hello -

I' pretty new to IIRF and have question regarding a rewrite rule I'm trying to get to work.

My current rule looks like this:

RewriteRule ^/([a-zA-Z_%+-]+)/([a-zA-Z_%+-]+)    ^/EventSchedule.aspx?ev=$1&ev2=$2 [I,L] (Does not work

What I'm trying to accomplish is: (example)

/lakers --> /EventSchedule.aspx?ev=lakers (this is an explicit example)

/suns --> /EventSchedule.aspx?ev=suns

I also have tested using an explicit rule such as "RewriteRule ^/lakers ^/EventSchedule.aspx?ev=lakers [I,L]" (this works, but I would really like a regex rule that would preclude me from writing all the explicit rules.)

I will also have urls such as /lakers/warriors

The error I'm getting is page cannot be found, however the url /eventschedule.aspx?ev=lakers does indeed work.

 

Thank you in advance for any help

Nov 29, 2010 at 8:58 AM

It looks like your rule is suggesting that you NEED to have 2 elements to it. The plus (+) sign means "one or more", which means that you need to pass it something like /lakers/warriors. This one should work.

Also, the 2nd part of your Regex is sending out the url starting with the ^

If you use the following:

RewriteRule ^/([a-zA-Z_%+-]+)   /EventSchedule.aspx?ev=$1 [I,L]

Then you should get the desired result on the /lakers url. If you want to use a second part of the url and make it optional, try using a * instead, which means zero or more, so your finished regex should look like:

RewriteRule ^/([a-zA-Z_%+-]+)/([a-zA-Z_%+-]*)    /EventSchedule.aspx?ev=$1&ev2=$2 [I,L]

Let me know how you get on.

HTH.

Nov 29, 2010 at 9:00 AM

Sorry, quick amend, need to make the / after the first part optional too.

RewriteRule ^/([a-zA-Z_%+-]+)/?([a-zA-Z_%+-]*)    /EventSchedule.aspx?ev=$1&ev2=$2 [I,L]

Maybe try using a Regex tool to test your expressions so you know what to expect on output.

Cheers.