Ever need to setup a Tuckey urlrewrite rule to detect if a query string exists? You can use the below snippet to append the query string and issue a permanent redirect. Note the difference in the ‘operator’ property of the ‘condition’ tag.
<rule enabled="true">
<condition type="query-string" operator="equal"></condition>
<from>^/find/$</from>
<to type="permanent-redirect" last="true">/search/?%{query-string}</to>
</rule>
<rule enabled="true">
<condition type="query-string" operator="notequal"></condition>
<from>^/find/$</from>
<to type="permanent-redirect" last="true">/search/</to>
</rule>
After implementing this into your ruleset, the following:
/find/
becomes
/search/
and the following:
/find/?q=javascript&foo=bar
becomes
/search/?q=javascript&foo=bar
Have a better idea on how to implement this functionality? Let me know in the comments.