Solved

How to Rewrite a URL to Another Website Retain Original URL IIS 7.5

Posted on 2014-04-15
8
1,241 Views
Last Modified: 2014-05-07
Hello,

I would like to know how to use Application Request Routing and IIS Rewrite to rewrite a URL like this:

http://test.ca/doing-business/licenses-and-permits/apply-for-a-permit-or-license/

to display the contents from another website without changing the original URL.  I need to be able to retain the css and javascript.

The other website URL is like this:
http://plposweb.ca/DEL/LMSPublic/

I'm using Windows Server 2008 R2, IIS 7.5, Application Request Routing Module and IIS Rewrite Module.

I can get it to work with a default Reverse Proxy rule so that requests to http://test.ca display the contents of the website http://plposweb.ca and retain the css and javascript.

I'm unsure how to refine this further so it will only perform the Reverse Proxy rewrite for requests to http://test.ca/doing-business/licenses-and-permits/apply-for-a-permit-or-license/ and display the contents from http://plposweb.ca/DEL/LMSPublic/ without changing the original URL.

Do I add Conditions to the rule or change the default pattern (.*)?  Specific examples would be very much appreciated.  I've looked at the IIS support website but I can't find examples for my particular situation.

Thanks.
0
Comment
Question by:COV-Webmaster
  • 5
  • 3
8 Comments
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 40004285
You are 99%?there, Just change the default pattern.
0
 

Author Comment

by:COV-Webmaster
ID: 40004398
That is where I'm running into problems.  I've successfully changed the pattern for the Inbound rule so it only rewrites for http://test.ca/doing-business/licenses-and-permits/apply-for-a-permit-or-license/.  I'm having problems getting the outbound rule to work.  I get a 404 Not Found error.  Do you have any advice on what I should put for the Outbound rule for the Reverse Proxy?
0
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 40004554
this is my web.config for one of my reverse proxies. It's easier to show than pasting in from the gui:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://old.company.com/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>



this is for a "new.company.com" url that is a reverse proxy for "old.company.com". I have no outbound rule, it works just fine.
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:COV-Webmaster
ID: 40004632
It works fine for me to reverse proxy from the root of test.vancouver.ca to plposweb.vancouver.ca.  The problem I'm having is that I need to have it only do the reverse proxy for one section of the website http://test.ca/doing-business/licenses-and-permits/apply-for-a-permit-or-license/ and have it go to a subfolder on the proxied site http://plposweb.ca/DEL/LMSPublic/.

Here is what I have for getting it to work for the root of both servers:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <outboundRules>
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                    <match filterByTags="A, Form, Img" pattern="^http(s)?://plposweb/(.*)" />
                    <action type="Rewrite" value="http{R:1}://test.vancouver.ca/{R:2}" />
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                </preConditions>
            </outboundRules>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://plposweb/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>


Here is what I have done to try to further refine the rule so it only rewrites if a visitor goes to http://test.ca/doing-business/licenses-and-permits/apply-for-a-permit-or-license/:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <outboundRules>
                <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1" enabled="true">
                    <match filterByTags="A, Form, Img, Input, Link" pattern="^http(s)?://plposweb/del/lmspublic/(.*)" />
                    <action type="Rewrite" value="http{R:1}://test.vancouver.ca/{R:2}" />
                    <conditions>
                    </conditions>
                </rule>
                <preConditions>
                    <preCondition name="ResponseIsHtml1">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                    <preCondition name="IsHTML">
                        <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                    </preCondition>
                </preConditions>
            </outboundRules>
            <rules>
                <rule name="ReverseProxyInboundRule1" enabled="true" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://plposweb/{R:1}" />
                    <conditions>
                        <add input="{URL}" pattern="^/doing-business/licenses-and-permits/apply-for-a-permit-or-license/" />
                    </conditions>
                </rule>
            </rules>
        </rewrite>
                   </system.webServer>
</configuration>

The inbound rule works and nothing but http://test.ca/doing-business/licenses-and-permits/apply-for-a-permit-or-license/ gets rewritten.  The remaining issue is that the Outbound rule doesn't work and I get a 404 Not Found error instead of displaying the contents from plposweb/del/lmspublic.

Any ideas on how to resolve this?
0
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 40004720
gotcha. I think you need to combine arr with url rewrite to get this working the way you want. Here is a nice writeup:
http://blogs.msdn.com/b/carlosag/archive/2010/04/02/setting-up-a-reverse-proxy-using-iis-url-rewrite-and-arr.aspx
0
 

Author Comment

by:COV-Webmaster
ID: 40018894
Thanks.  I was away for a few days of vacation.  I'll take a look at this article and see if I can get it to work.
0
 

Accepted Solution

by:
COV-Webmaster earned 0 total points
ID: 40037916
The blog provided did not help with our particular situation.  We did need to combine ARR with URL Rewrite which I already knew.  What I was trying to get from my question was how to write the rules.  We ended up getting help from Microsoft Premium Support and it took a Microsoft Engineer a few hours how to figure out how to get the rules to work for our situation.  None of the blogs or support articles covered what we needed to do.
0
 

Author Closing Comment

by:COV-Webmaster
ID: 40046626
I accepted my own solution because I did not get the assistance that I needed to resolve my problem.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question