0

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

  • See what FRT says, https://learn.microsoft.com/en-us/iis/extensions/url-rewrite-module/using-failed-request-tracing-to-trace-rewrite-rules – Lex Li Sep 07 '20 at 01:26

2 Answers2

0

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.

Bruce Zhang
  • 2,880
  • 1
  • 5
  • 11
0

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

  • I will set up tracing in the next day or so to see if that helps me see where it is failing – Universal4 Sep 07 '20 at 08:08
  • Has your problem been solved? If it is solved, please mark the correct answer. This will help others who may have similar problems. – Bruce Zhang Sep 11 '20 at 09:28
  • Could you show me your fail request tracing so that I can find the issue? Also please tell me which rule doesn't work. – Bruce Zhang Sep 14 '20 at 09:54
  • I actually just fixed this without many changes. As soon as I changed the action from rewrite to redirect, the pages that needed to point at root all work fine now. I think it was strange that any pages pointed at root, or index.php did not work but any that pointed at any page other then index or root worked fine no matter what the extension was. But with redirect they all work fine now. As for what the tracing reported. – Universal4 Sep 15 '20 at 10:02
  • Only in the tracking report can you see in detail which rules match and which do not match during the rewriting process, what the initial URL is, and what is after the rewriting is successful. – Bruce Zhang Sep 17 '20 at 09:47
  • The tracing did not show any rules that did not pattern match, but as I said the change to redirect fixed the issue, and if you look at logic, if the pattern was incorrect, how is the pattern correct for redirect but not rewrite. – Universal4 Sep 18 '20 at 19:45
  • It is strange because whatever rewrite or redirect, they use the same pattern just different action. If you want to find out the where the error is, you can get remote support from here.https://support.microsoft.com/ – Bruce Zhang Sep 28 '20 at 09:39
  • While I agree that changing ONLY the action and not the pattern, doesn't make sense it is in fact what fixed the issue. – Universal4 Sep 29 '20 at 21:17
  • If it is useful, please post it as answer, so that it can help others with similar problems. – Bruce Zhang Oct 07 '20 at 06:57