Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm hosting a site where I would like for various reasons to have http://mydomain.com automatically redirect to http://mydomain.com/web while at the same time still allowing http://mydomain.com/foo.html to be served.

Using HTTP Redirect from IIS 7 I seem to be creating an endless redirect loop. Would you have any hints for me?

share|improve this question

migrated from superuser.com Oct 2 '11 at 5:17

This question came from our site for computer enthusiasts and power users.

1 Answer 1

up vote 1 down vote accepted

I assume you only want request for / to be redirected. In the case, check for an empty URL and then redirect to /web/ as shown in this web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect to /web" stopProcessing="true">
                    <match url="^$" />
                    <action type="Redirect" url="/web/" redirectType="Found" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

If you have moved your entire site under /web/ and want to redirect every old URL to it's new URL under /web/ except those that have a matching file or directory, you simply check all URL's that don't start with web/ and don't match a file and directory and redirect those:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect to /web" stopProcessing="true">
                    <match url="^web/" negate="true" />
                    <action type="Redirect" url="/web{REQUEST_URI}" appendQueryString="false" redirectType="Found" />
                    <conditions>
                        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                    </conditions>
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.