match URL with and without querystring

Topics: Developer Forum, User Forum
Jan 19, 2010 at 9:36 AM

I want to match a URL (e.g. test.cfm) without any querystring and redirect it to lets say /testing/index.html

and I want to match the same URL (e.g. test.cfm?var=1&var2=4 . ie with querystring) and redirect it to /index.cfm?testing=true

I can do only one of these currently but cant get both working .....one works, the other breaks..

can someone help ?

 

Coordinator
Jan 21, 2010 at 7:25 PM
Edited Jan 21, 2010 at 7:26 PM

Try this:

RewriteRule  ^/test.cfm$   /testing/index.html     [L]
RewriteRule ^/test.cfm     /index.cfm?testing=true [L]

Explanation: the first rule captures an incoming URL that is /test.cfm, with nothing following it. The $ indicates end-of-string, which means, there is nothing following test.cfm. The [L} modifier says that there will be no more iterations performed when this rule fires. Normally in IIRF, the output of a rule that fires is cascaded through the set of rules again. But the [L] tells IIRF to NOT do that.

The second rule also matches test.cfm, but there is no trailinig $ in the pattern. Since the first rule slurped up all the "bare" test.cfm requests, the only ones remainnig will have something following the test.cfm. A Slash, a question mark, or even more alpha. /test.cfm/something will match, as will /test.cfm?anything, and /test.cfmabcdefg.

Last note: In general it helps to show what you have tried, when asking for help.

Jan 21, 2010 at 7:33 PM

Thanks, that worked.

I did this

RedirectRule /test.cfm$ /testing/index.html [R=301]
RedirectRule /test.cfm /index.cfm?mode=test [R=301]
And it works. Thanks a lot.