Using IIRF to either add or replace a value in the URL

Apr 20, 2011 at 12:31 AM
Edited Apr 21, 2011 at 3:37 PM

I would like to know if it is possible for IIRF to rewrite a url so it either adds a variable to the url if it does not exist or if the variable does exist to replace its value.

I'm using SharePoint 2007 and the out of the box Workflows do not append the OpenIn to a url for InfoPath forms, and what ends up happening is that Internet Explorer prompts to download the form, then opens in InfoPath. Even if I have Open in web browser.

So I would like to add the OpenIn=Browser to those URLs by rewriting them, if it does not exist. If OpenIn does exist, ensure that it says OpenIn=Browser.

Thanks for any ideas on this; I'm not much of a regex genius. (Or spelling genius either, it would seem)

Coordinator
Apr 20, 2011 at 1:07 AM

yes, it is possible to do what you want. Hard to know exactly which rules to use, but something like this is pretty close:

# rewrite all URLs with OpenIn query string param, to specify "Browser"
RewriteRule ^/([^\?]+)?(OpenIn)   ^/$1?OpenIn=Browser  [L]

# Rewrite other Urls (that lack OpenIn) to specify OpenIn=Browser
RewriteRule ^/([^\?]+)?? ^/$1?OpenIn=Browser   [L,QSA]

The edge cases not handled: when you have a URL with multiple query string params, one of which is OpenIn and the others are not, you'll need to deal with that, possibly with a separate rule. I'm not sure this is even possible, and not sure what you'd want to do about this sort of incoming URL.

Also you may have other cases you want to cover. The only way to know is to test it.

Good luck

Apr 21, 2011 at 5:04 PM

Hey thanks! I'll have to definately check it out then. It's been a rather annoying thorn in my SharePoint side.

Apr 21, 2011 at 8:34 PM
Cheeso wrote:

yes, it is possible to do what you want. Hard to know exactly which rules to use, but something like this is pretty close:

# rewrite all URLs with OpenIn query string param, to specify "Browser"
RewriteRule ^/([^\?]+)?(OpenIn)   ^/$1?OpenIn=Browser  [L]

# Rewrite other Urls (that lack OpenIn) to specify OpenIn=Browser
RewriteRule ^/([^\?]+)?? ^/$1?OpenIn=Browser   [L,QSA]

The edge cases not handled: when you have a URL with multiple query string params, one of which is OpenIn and the others are not, you'll need to deal with that, possibly with a separate rule. I'm not sure this is even possible, and not sure what you'd want to do about this sort of incoming URL.

Also you may have other cases you want to cover. The only way to know is to test it.

Good luck


Perhaps I'm doing something wrong...

I found the TesrtDriver gizmo and took your first example and in the SampleUrls.text file I put in

/FormServer.aspx?OpenIn=Car /FormServer.aspx?OpenIn=Browser

In the iirf.ini file I have your example of -

RewriteRule ^/([^\?]+)?(OpenIn)   ^/$1?OpenIn=Browser

Ran it and got the following output:

TestDriver: linked with 'Ionic ISAPI Rewriting Filter (IIRF) 2.1.1.26 x64 RELEA
E'.
TestDriver: The IIRF library was built on 'Apr 18 2011 01:41:16'

Trying to read config at '.\Iirf.ini'
done reading new config
Processing URLs...(.\\SampleUrls.txt)


***
Retrieving server variable that is not supported by TestDriver (SCRIPT_NAME)

NO REWRITE '/FormServer.aspx?OpenIn=Car' ==> --
ERROR expected(/FormServer.aspx?OpenIn=Browser)
        actual(NO REWRITE)


1 Errors in 1 Total Trials

I'll keep futzing with it, but if you have any ideas, it would be great.

Thanks!

Apr 21, 2011 at 9:31 PM

I think I know what's going on; the url I have has spaces in it (It's a sharepoint url thing) and that's mucking it up.