How can I make this rewrite rule so that it can accept querystring?

0

I have a url rewrite rule that uses map method.

            <rewriteMap name="Pages">
                <add key="/search" value="/search.asp" />
            </rewriteMap>




            <rule name="Rewrite rule1 for Pages">
                <match url=".*" />
                <conditions>
                    <add input="{Pages:{REQUEST_URI}}" pattern="(.+)" />
                </conditions>
                <action type="Rewrite" url="{C:1}" appendQueryString="true" />
            </rule>

My problem is when I use this page like below, I get error:

/search?keyword=math

I get HTTP Error 404.0 - Not Found

Detailed Error Information: Module IIS Web Core Notification MapRequestHandler Handler StaticFile Error Code 0x80070002 Requested URL http://localhost:85/search?keyword=math Physical Path D:\webs\V5ST\HTML\search Logon Method Anonymous Logon User Anonymous

How can I make this so that whatever querystring is passed to search.asp?

url-rewriting
iis-7.5
asked on Stack Overflow May 15, 2019 by Savaş Zorlu • edited May 17, 2019 by Savaş Zorlu

1 Answer

1

You could use below rewrite rule:

 <rule name="query string redirect" enabled="true" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{REQUEST_URI}" pattern="search\?(.*)" />
                </conditions>
                <action type="Rewrite" url="http://localhost:132/search.asp?{C:1}" appendQueryString="false" />
            </rule>

Regards, Jalpa

answered on Stack Overflow May 17, 2019 by Jalpa Panchal

User contributions licensed under CC BY-SA 3.0