Search code examples
regexhttp-redirectiisurl-rewritingweb-config

URL Rewrite iis server


I want to rewrite a url to index.html. the web.config below does the job until first path. eg:- test.com/test1 to test.com/index.html but it doesnt work with multiple paths. eg:- test.com/test1/test2

my current web.config

<configuration>
    <system.webServer>
        <rewrite>
        <rules>
            <rule name="redirect all requests" stopProcessing="true">
                <match url="^(.*)$" ignoreCase="false" />
                <conditions logicalGrouping="MatchAll">
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
                </conditions>
                <action type="Rewrite" url="index.html" appendQueryString="true" />
            </rule>
        </rules>
    </rewrite>
    </system.webServer>
</configuration>

I'm not sure what I'm missing here. Please if any of you know, write the correct web.config. Thank you.


Solution

  • You can try this rule:

    <rule name="test" stopProcessing="true">                    
      <match url="(.*)" />
        <conditions>
           <add input="{REQUEST_URI}" pattern="^/([^/]+)" />
        </conditions>
      <action type="Redirect" url="http://test.com/{C:1}/index.com" redirectType="Found" />
    </rule>