Solved

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

Posted on 2014-04-15
8
1,296 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

617 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