Solved

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

Posted on 2011-02-23
8
2,343 Views
Last Modified: 2012-05-11
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?
 iis 7.5 url rewrite
0
Comment
Question by:COV-Webmaster
  • 4
  • 4
8 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34965470
Perhaps this would work:
<add input="{REQUEST_URI}" pattern="^$" />

Open in new window

0
 

Author Comment

by:COV-Webmaster
ID: 34965694
Thanks Kaufmed.  It would make sense that that would work, but for whatever reason it doesn’t.
This is what I tried:

<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>

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34966759
Now that I think about it, why wouldn't you just specify the "default document" to be index.htm ?
0
 

Author Comment

by:COV-Webmaster
ID: 34970608
The index.htm is specified as the default document. The URL Rewriting rules are processed before the default document or any document is loaded. The default document is never loaded because I have other rules in place.
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34971762
>> The URL Rewriting rules are processed before the default document or any document is loaded.

Right, but if the user doesn't supply a URI (i.e. they go to the website root), then none of the rules should match, and the default document should be loaded. I could be missing something though.
0
 

Accepted Solution

by:
COV-Webmaster earned 0 total points
ID: 34981764
Here is how I got it working.  The rule below will allow all of the other rules below it to still process and will allow the root document to be loaded when I hit the http://domain.com/ root site:

<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>

Open in new window

0
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 34982948
Cool. Glad you found a solution  = )
0
 

Author Closing Comment

by:COV-Webmaster
ID: 35015481
This rule works.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Running classic asp applications under Windows Server 2008 R2 (x64) and IIS 7 is not as easy as one may think. It took me a while to figure it out while getting error 8002801d a few times. After you install the OS you will need to install the fol…
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

912 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now