Redirect incoming requests to specific URLs in IIS 7

19,509

This rule will redirect SPECIFIC incoming request to specific URL:

<system.webServer>
    <rewrite>
        <rules>
            <rule name="Redirect Specific Page" stopProcessing="true">
                <match url="^blog/post/5$" />
                <action type="Redirect" url="http://other.domainxyz.com/site/5" />
            </rule>
        </rules>
    </rewrite>
</system.webServer>

UPDATE: I have merged them together -- just update it with real URLs:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
  <system.webServer>
        <rewrite>
            <rules>
                <rule name="home" stopProcessing="true">
                    <match url="^$" />
                    <action type="Redirect" url="http://yojimbo87.github.com/" />
                </rule>
                <rule name="about" stopProcessing="true">
                    <match url="^Blog/About$" />
                    <action type="Redirect" url="http://yojimbo87.github.com/about/about.html" />
                </rule>
                <rule name="Redirect Specific Page" stopProcessing="true">
                    <match url="^blog/post/5$" />
                    <action type="Redirect" url="http://other.domainxyz.com/site/5" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
Share:
19,509

Related videos on Youtube

yojimbo87
Author by

yojimbo87

2B || !2B, that is the statement.

Updated on September 18, 2022

Comments

  • yojimbo87
    yojimbo87 over 1 year

    I found in IIS HTTP Redirect feature, but I can only redirect all incoming requests to specific destination. Is it possible to redirect incoming requests to specific URLs in IIS? For example:

    my.domain.com/blog/about -> other.domainxyz.com/site/about
    my.domain.com/blog/post/5 -> other.domainxyz.com/site/5
    

    UPDATE

    This is how web.config looks like:

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
      <system.webServer>
            <rewrite>
                <rules>
                    <rule name="home" stopProcessing="true">
                        <match url="^$" />
                        <action type="Redirect" url="http://yojimbo87.github.com/" />
                    </rule>
                    <rule name="about" stopProcessing="true">
                        <match url="^Blog/About$" />
                        <action type="Redirect" url="http://yojimbo87.github.com/about/about.html" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    

    I havent't found URL Rewrite module among the Role Services although HTTP Redirection is there.

    • LazyOne
      LazyOne almost 13 years
      Are both domains bound to the same site .. or they are 2 different sites (I'm asking if domain name should be a condition when creating a rule)?
    • yojimbo87
      yojimbo87 almost 13 years
      Domains are on different sites separated on different machines. I can control only the redirection on the IIS machine.
  • yojimbo87
    yojimbo87 almost 13 years
    When I add this into web.config inside configuration element it starts giving me "500 - Internal server error" no matter which combination of url match I use.
  • LazyOne
    LazyOne almost 13 years
    @yojimbo87 1) You need to have URL Rewrite module installed (which you should have already, considering "IIS 7.5" tag). 2) I hope you have not added it "as is"? If you have some rewrite rules already, then you need to add just <rule> part into appropriate place. In any case -- the rule is 100% working as I have tested it before posting. If you can -- please provide your web.config (no need for whole content -- just enough to see the structure) so I can guide you where it needs to be placed (in case it is the actual problem).
  • yojimbo87
    yojimbo87 almost 13 years
    Question updated.
  • LazyOne
    LazyOne almost 13 years
    @yojimbo87 See updated answer. If your web.config worked before it should work now as well.
  • yojimbo87
    yojimbo87 almost 13 years
    Still no luck. If I try to go to IIS manager and want to see Failed Request Tracing Rules it gives me an error pointing to web.config. This looks strange cause other people have also issues with it.
  • LazyOne
    LazyOne almost 13 years
    @yojimbo87 Unfortunately I cannot tell you why it does not work -- I can only confirm that I did copy-paste it from my answer and it worked on both Windows 7 and Windows Server 2008 (IIS 7.5 and IIS 7.0 accordingly -- both with URL Rewrite v2 module installed). Maybe access rights? If you have Windows 7 test it locally yourself.
  • LazyOne
    LazyOne almost 13 years
    @yojimbo87 "Failed Request Tracing Rules it gives me an error pointing to web.config" If you can display DETAILED error page, it should point into exact line or display the reason why it rejects web.config. I don't have GoDaddy hosting account and cannot help you on this.
  • yojimbo87
    yojimbo87 almost 13 years
    Sorry for the noise I thought that rewrite module supposed to be installed through Role Services in Server Manager. After I installed the module from here it work as it should. Thanks for patience and help.