2

I have a situation where I want to use IIS 8 URL Rewrite to point requests for a service from one web application to another. The services are called by an iPhone app, and are hard coded within its code, so for legacy reasons the URL www.myownsite.com/iPhone/myService.asmx must provide the service. However, the main www website is becoming an increasingly complex web application, laborious to deploy (it's actually a Telerik Sitefinity site) and so for ease of deployment of services bug fixes I'd like to move them to a separate site - called services.myownsite.com. Future apps will reference this directly, but I still need to cater for the legacy ones which need the www address.

The two sites sit on the same iis server and share an ip but have different host headers. The service works fine when called directly via the URL

services.myownsite.com/iPhone/myService.asmx

My desire was to use URL Rewrite to point the www. requests to the services. equivalent.

Here's the issue - I can get URL rewrite to work, but only when the rewritten URL is a relative URL. I cannot rewrite to ones containing http: //

This is rather annoying, as I was following the instructions closely in this msdn blog post which suggested that such an approach would be fine http://blogs.msdn.com/b/carlosag/archive/2010/04/02/setting-up-a-reverse-proxy-using-iis-url-rewrite-and-arr.aspx

Here is an example of what I mean - I tried something simpler to see how it worked. The code below successfully rewrites the URL to another relative URL within the same site, in this case another service

                <rule name="Authentication Service" stopProcessing="true">
                <match url="iPhone/(.*)" />
                <action type="Rewrite" url="/secure/services/anotherservice.asmx" logRewrittenUrl="true" /> 
            </rule>

However, if I try to use an absolute URL - a first step towards being anble to change the URL to another site - it fails. Example below

            <rule name="Authentication Service" stopProcessing="true">
                <match url="iPhone/(.*)" />
                <action type="Rewrite" url="http://www.myownsite.com/secure/services/anotherservice.asmx" logRewrittenUrl="true" /> 
            </rule>

What I'd really like is to have the URL attribute work with values like

http://services.myownsite.com/secure/services/anotherservice.asmx. 

I can happily use the regular expression back references to build up rewrite URLs, I'm just tearing my hair out as to why I can't use anything other than a relative URL in the rewrite.

Help please! Thanks

Andy R
  • 31
  • 1
  • 4
  • Personally - I'd try to do it more simple with a 301 redirect in the IIS. URL Rerwrite is generally for making friendly urls and mapping an external to an internal. Not moving a site, which should be done with 301 redirects to update search engine references. – Allan S. Hansen Dec 11 '14 at 10:53
  • A 301 redirect isn't going to work here, because the iPhone application calling it isn't intelligent enough to recognise the redirect and change its call accordingly – Andy R Dec 11 '14 at 11:01
  • Irrespective of whether Andy R's approach is good or not, I'm still interested in knowing how to use the IIS Rewrite module to create a rule based on a Rewrite Map that contains absolute URLs as targets. I just get HTTP 500. – Chris Peckham Feb 19 '15 at 11:46
  • 2
    Have you found a solution here? I'm having the same problem ... – mosu Mar 03 '15 at 22:59

1 Answers1

3

I had a similar hair-tearing experience that I solved as follows:

  1. Install the Application Request Routing extension for IIS.
  2. In IIS Manager, open IIS > Application Request Routing Cache. Go to Server Proxy Settings and check Enable proxy.

This checkbox lets IIS act a reverse proxy, so that I can now rewrite the URL to an absolute URL instead of just a relative one. (My use case is to let a client request https://foo.bar.baz/resource and let it be handled by https://foo.bar.baz:5678/resource, where 5678 is a port blocked by my firewall.)

Gary Sheppard
  • 4,764
  • 3
  • 25
  • 35