Must be a better way to write this...

Topics: User Forum
Jul 23, 2008 at 2:52 PM
Hi,

I have some rules that I think look quite ugly. I suspect they can be refrased into one single rule, I just don't see how. Any Ideas?

RewriteRule ^/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/.*/goto/$ /SomePage.aspx?$1=$2&$3=$4&$5=$6&$7=$8 [I]
RewriteRule ^/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/goto/$ /SomePage.aspx?$1=$2&$3=$4&$5=$6&$7=$8 [I]
RewriteRule ^/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/.*/goto/$ /SomePage.aspx?$1=$2&$3=$4&$5=$6 [I]
RewriteRule ^/(.*)/(.*)/(.*)/(.*)/(.*)/(.*)/goto/$ /SomePage.aspx?$1=$2&$3=$4&$5=$6 [I]
RewriteRule ^/(.*)/(.*)/(.*)/(.*)/.*/goto/$ /SomePage.aspx?$1=$2&$3=$4 [I]
RewriteRule ^/(.*)/(.*)/(.*)/(.*)/goto/$ /SomePage.aspx?$1=$2&$3=$4 [I]
RewriteRule ^/(.*)/(.*)/.*/goto/$ /SomePage.aspx?$1=$2 [I]
RewriteRule ^/(.*)/(.*)/goto/$ /SomePage.aspx?$1=$2 [I]

Thanks.
Coordinator
Jul 23, 2008 at 4:31 PM
Maybe look here:
http://www.codeplex.com/IIRF/Wiki/View.aspx?title=Examples&referringTitle=Home

And particularly at the example that shows how to map between URL Segments and Query params.
It accomplishes what you are doing, iteratively. 

Also consider trying out the TestDriver.exe program, it lets you test the Rules without using a server.
Jul 25, 2008 at 8:59 AM
I looked at that earlier, but somehow managed to not get it working. I gave it another try, since you recommended it, and now I got it working. It's hard to know when you're on the right track when you're new to this.

Thanks!
Coordinator
Jul 28, 2008 at 6:21 PM
I agree, regular expressions are a black art.
Combine that with the operation of an ISAPI filter, and all the magic of http messages, and multiple cooperating pieces of software, loggers and proxies, and so on...
yes, it can get tricky.

I hope the TestDriver program is of some help.