Solved

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

Posted on 2014-04-15
8
1,223 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 38

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 38

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
 

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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 38

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now