0

I need to redirect a url called "www.mydomain.com" to "www.mydomain.com/index.php?id=1". I configured http redirection on IIS but I get Too many redirect error. I also tried doing it via url rewrite module but I get same error. If I check the box append query string, the url shows "www.mydomain.com/index.php?id=1&id=1&id=1&id=1...". The &id=1 shows many times. My web config rewrite rule is as follows:

<rules>
                <rule name="redirect" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Redirect" url="/index.php?id=1" appendQueryString="true" />
                    <conditions>
                    </conditions>
                </rule>
</rules>

Can someone help me. I have been trying this all day. Thank you.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
Anonymous
  • 1
  • 1
  • 5
  • This is mainly because there is a problem with your rewrite rules, which leads to circular redirection. You need to modify your rewrite rules. – Ding Peng Dec 16 '20 at 07:15

1 Answers1

0

You're redirecting an empty path. So technically you'll match on every redirect and continue mapping the query string to the end.

  1. In the pattern box provided add the REGEX expressions for empty path. It's one of these combos:

    • ^$
    • ^/?$
    • ^\/?$ (I don't think this escape is necessary, but worth trying if it works.)
  2. You can also alter the web.config to match on the empty path and then redirect.

    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <rules>
                    <rule name="Redirect to /index.php?id=1" stopProcessing="true">
                        <match url="^$" />
                        <action type="Redirect" url="/index.php?id=1" redirectType="Found" />
                    </rule>
                </rules>
            </rewrite>
        </system.webServer>
    </configuration>
    
  3. Another viable option....you didn't list the transport layer (HTTP | HTTPS), but in the event that you're redirecting from HTTP -> HTTPS you can try this solution: IIS URL Rewrite module repeats query string

Kota
  • 157
  • 7
  • I wanted to know what does these means though? ^$ ^/?$ ^\/?$ (.*) * And if I wanted to redirect to the url but with https, should I create another rule? – Anonymous Dec 15 '20 at 09:51