Dreamray
Dreamray

Reputation: 11

iis7.5, web.config how to redirect not exist file(page) to another page?

I'm using iis-7.5 and web.config file.

I want to redirect "somepage.asp?id=63" to "somepage/10.html".

My web.config is like this:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="301 Redirect 2" stopProcessing="true">
                    <match url="somepage.asp?id=63" />
                    <action type="Redirect" url="somepage/10.html" redirectType="Permanent" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

it didn't work, when I change <match url="somepage.asp?id=63" /> to <match url="somepage.asp" />, (delete ?id=63) , it worked, why? how can i do?

Upvotes: 1

Views: 621

Answers (1)

Brando Zhang
Brando Zhang

Reputation: 28192

As far as I know, the url rewrite match url pattern doesn't match query string.

If you want to redirect the url according to the query string, I suggest you could try to use condition.

More details, you could refer to below url rewrite rule:

            <rule name="Redirect according to query string" stopProcessing="true">
                <match url="somepage.asp" />
                <conditions>
                    <add input="{QUERY_STRING}" pattern="id=63" />
                </conditions>
                <action type="Redirect" url="somepage/10.html" appendQueryString="false" />
            </rule>

Upvotes: 1

Related Questions