IIS redirect maps not working for root destination

209 views Asked by At

I am having some trouble getting rewrite pas to work correctly when I point the destination to root.

If I point at a /page/ destination t seems to work correctly, but if I point at / it does not. Below is what I have in my web.config

    <rewrite>
    <rewriteMaps>
        <rewriteMap name="StaticRewrites">
            <add key="/1" value="/article.aspx?id=1&amp;title=some-title" />
            <add key="/random_page.htm" value="/" />
            <add key="/friends.htm" value="index.php" />
            <add key="/page_2.htm" value="/index.php" />
            <add key="/some_other_page.htm" value="/some_other_page/" />
            <add key="/some_page_test.htm" value="/test21.php" />
            <add key="/2nd_page_test.htm" value="/test.txt" />
            <add key="/3rd_page_test" value="/test1.htm" />
            <add key="/4th_page_test.htm" value="article.aspx?id=1&amp;title=some-title" />
            <add key="/root_page_again.htm" value="/" />
        </rewriteMap>
</rewriteMaps>
<rules>     
    <rule name="Rewrite rule1 for StaticRewrites">
            <match url="(.*)" />
            <conditions>
                <add input="{StaticRewrites:{REQUEST_URI}}" pattern="(.+)" />
            </conditions>
            <action type="Rewrite" url="{C:1}" appendQueryString="false" />
    </rule>
    <rule name="WordPress: http://123.123.12.123" patternSyntax="Wildcard">
        <match url="*" />
        <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        </conditions>
            <action type="Rewrite" url="index.php/{R:0}" />
    </rule>     
</rules>
</rewrite>

The 1st one works
The 2nd, 3rd, 4th does not work
The 5th, 6th, 7th, 8th and 9th does work
The 10th or last one does not

I have edited a few obvious spots for privacy IIS 8.5

2

There are 2 answers

0
Bruce Zhang On

The 1st works because it matches 1st rule.

The 2nd doesn’t work because you didn’t set default document. It matches 1st rule ,if you set default document, it will rewrite to http://localhost:xx/ and display default document.

The 3rd and 4th match 1st rule, both rewrite to http://localhsot:xx/index.php

The 5th,6th,7th,8th all match 1st and 2nd rule, but rewrite to http://localhsot:xx/index.php//”value” and display index.php.

The 9th matched 1st rule and rewrite to http://localhsot:xx/ article.aspx?id=1&title=some-title.

The 10th is the same as the 2nd.

You can open fail request tracing which will record the entire rewriting process including whether it meets the rules and whether to rewrite.

9
Universal4 On

I apologize I had not posted the beginning of the config file. I assumed everyone would understand default document has been set, since the entire site would not load without it.

Here is the beginning part of the web.config I had not posted earlier

    <configuration>
  <system.webServer>
    <defaultDocument>
      <files>
        <add value="index.php" />
      </files>
    </defaultDocument>
    <rewrite>
    <rewriteMap name="StaticRewrites">

I appreciate any help in this matter, and know I must be missing something simple since most rules do in fact work