locked
Setup IIS 7.5 URL Rewrite to redirect root request to index.htm RRS feed

  • Question

  • User-738022746 posted

     I have several re-write rules setup using the IIS 7.5 URL Rewrite add-on.  All of the re-writes are working fine.  Currently with all of these re-writes enabled, when a user requests http://domain.com/ they are being redirected to another server. I want them to be re-directed to another server when they match one of my other regular expressions.  When a user does not enter in anything (ie: hits the root of the site http://domain.com/ ), I want them to be transferred to the index.htm file on the same server. Something like this could easily be done using the Apache Mod Rewrite using a regex like "^/", however, IIS 7.5's seems to match the URL path after the first "/" that is requested.

    Is there any way to do this?  Below is what I have tried so far.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                <rule name="Index Request" enabled="true" stopProcessing="true">
                        <match url="^/" />
                        <conditions>
                            <add input="{REQUEST_URI}" pattern="^/" />
                        </conditions>
                        <action type="Redirect" url="http://domain.com/index.htm" logRewrittenUrl="true" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>

    Any suggestions?

    Thursday, February 24, 2011 12:45 PM

Answers

  • User744767459 posted

    Hi, 

               <rule name="Index Request" enabled="true" stopProcessing="true">
                        <match url="^/" />
                        <conditions>
                            <add input="{REQUEST_URI}" pattern="^/" />
                        </conditions>
                        <action type="Redirect" url="http://domain.com/index.htm" logRewrittenUrl="true" />
                    </rule>

    You can use the following rule:

    <rule name="Index Request" enabled="true" stopProcessing="true">
        <match url="^$" />
        <action type="Redirect" url="http://domain.com/index.htm" logRewrittenUrl="true" />
    </rule>

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Monday, February 28, 2011 2:40 AM

All replies

  • User-403641541 posted
    1) make match url (.*) 2) add condition {REQUEST_URL} is blank or just a slash. (/+)
    Friday, February 25, 2011 6:47 AM
  • User-738022746 posted

    Thanks for your help.  What you suggested will work, but then all of the rules below it will not work because it redirects everything.  I made some modifications to your suggestion and got it working.

     <rule name="Index Request" enabled="true" stopProcessing="true">

              <match url="^(.+)$" negate="true" />

                     <conditions>

                           <add input="{REQUEST_URL}" pattern="^(.+)$" negate="true" />

                     </conditions>

              <action type="None" logRewrittenUrl="true" />

    </rule>

    Friday, February 25, 2011 12:58 PM
  • User744767459 posted

    Hi, 

               <rule name="Index Request" enabled="true" stopProcessing="true">
                        <match url="^/" />
                        <conditions>
                            <add input="{REQUEST_URI}" pattern="^/" />
                        </conditions>
                        <action type="Redirect" url="http://domain.com/index.htm" logRewrittenUrl="true" />
                    </rule>

    You can use the following rule:

    <rule name="Index Request" enabled="true" stopProcessing="true">
        <match url="^$" />
        <action type="Redirect" url="http://domain.com/index.htm" logRewrittenUrl="true" />
    </rule>

    • Marked as answer by Anonymous Tuesday, September 28, 2021 12:00 AM
    Monday, February 28, 2011 2:40 AM