Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-04-15
8
Medium Priority
?
1,357 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
The viewer will learn how to count occurrences of each item in an array.
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…
Suggested Courses

824 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