Redirecting to new URL with IIS

In IIS there is a trick for redirecting requests to a new URL including original path and query string. This trick worked on IIS 6. Today I tried this with IIS 7.5 on Windows Server 2008 R2. It’s still working!!!

 

Demo:

1. You have an SharePoint with host header “sharepoint.local” and a Shared Documents library with a single document. This link will open the document properties view form:

http://sharepoint.local/Shared%20Documents/Forms/DispForm.aspx?ID=1&Source=http%3A%2F%2Fsharepoint%2Elocal%2FShared%2520Documents%2FForms%2FAllItems%2Easpx&RootFolder=%2FShared%20Documents&ContentTypeId=0x010100293CE4623453F044AE694E186F090B7C&IsDlg=1

2. Now you create a IIS redirect for “http://sharepoint-redirect.local”:

Therefore you create a new web application in IIS:

image

Now you add “Http Redirect” functionality to the web application:

image

image

Click “Apply” after configuration.

3. If you test it in the browser with URLs like http://sharepoint-redirect.local/Shared%20Documents it works as expected. You get http://sharepoint.local/Shared%20Documents

4. But if you try the link from above you get an unexpected result:

http://sharepoint-redirect.local/Shared%20Documents/Forms/DispForm.aspx?ID=1&Source=http%3A%2F%2Fsharepoint%2Elocal%2FShared%2520Documents%2FForms%2FAllItems%2Easpx&RootFolder=%2FShared%20Documents&ContentTypeId=0x010100293CE4623453F044AE694E186F090B7C&IsDlg=1

redirected to:

http://sharepoint.local/SitePages/Home.aspx

5. If you uncheck (and “Apply”) the following checkbox in the HTTP Redirect settings of the web application it looks a little bit better:

image

 

http://sharepoint-redirect.local/Shared%20Documents/Forms/DispForm.aspx?ID=1&Source=http%3A%2F%2Fsharepoint%2Elocal%2FShared%2520Documents%2FForms%2FAllItems%2Easpx&RootFolder=%2FShared%20Documents&ContentTypeId=0x010100293CE4623453F044AE694E186F090B7C&IsDlg=1

redirected to:

http://sharepoint.local/Shared%20Documents/Forms/DispForm.aspx

The URL is correct but the query string is missing. So the form is empty:

image

6. Now the “old” IIS trick for HTTP Redirect:

Use tokens $S$Q in the redirect URL!

$S = Path

$Q = Query String

image

Now it HTTP Redirect works as expected!

http://sharepoint-redirect.local/Shared%20Documents/Forms/DispForm.aspx?ID=1&Source=http%3A%2F%2Fsharepoint%2Elocal%2FShared%2520Documents%2FForms%2FAllItems%2Easpx&RootFolder=%2FShared%20Documents&ContentTypeId=0x010100293CE4623453F044AE694E186F090B7C&IsDlg=1

redirected to:

http://sharepoint.local/Shared%20Documents/Forms/DispForm.aspx?ID=1&Source=http%3A%2F%2Fsharepoint%2Elocal%2FShared%2520Documents%2FForms%2FAllItems%2Easpx&RootFolder=%2FShared%20Documents&ContentTypeId=0x010100293CE4623453F044AE694E186F090B7C&IsDlg=1/Shared%20Documents/Forms/DispForm.aspx

 

image

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.