Solved

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

Posted on 2014-04-15
8
1,215 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
Comment Utility
You are 99%?there, Just change the default pattern.
0
 

Author Comment

by:COV-Webmaster
Comment Utility
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
Comment Utility
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
Comment Utility
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 38

Expert Comment

by:Aaron Tomosky
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
I accepted my own solution because I did not get the assistance that I needed to resolve my problem.
0

Featured Post

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.

Join & Write a Comment

Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
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…
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…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

771 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

10 Experts available now in Live!

Get 1:1 Help Now