Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS7 URL Rewriting to different domain, exact match

I basically want to match the exact address

http://www.example.com/mysite

and redirect it to

http://www.example2.com/something/something

If possible I want to be able to do it with IIS because I have coded an internal rewriting module for example.com that rewrites user friendly URLS to aspx pages, and I don't want any interference with the other site.

NINJA EDIT:

I want to keep the address as http://www.example.com/mysite so I need to rewrite it not redirect it.

like image 405
James Hay Avatar asked Nov 02 '11 01:11

James Hay


People also ask

What is Request_uri in URL Rewrite?

Returns exact URL what you requested. For example, if you have default.aspx file in the root and you will access your website root.

What is the difference between URL Rewrite and redirect?

Simply put, a redirect is a client-side request to have the web browser go to another URL. This means that the URL that you see in the browser will update to the new URL. A rewrite is a server-side rewrite of the URL before it's fully processed by IIS.


1 Answers

This should do the job:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect mysite" stopProcessing="true">
                    <match url="^mysite$" />
                    <conditions>
                        <add input="{HTTP_HOST}" pattern="^www\.example\.com$" />
                    </conditions>
                    <action type="Redirect" url="http://www.example2.com/something/something" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
like image 162
Marco Miltenburg Avatar answered Oct 03 '22 02:10

Marco Miltenburg