简体   繁体   中英

URL Rewrite with Web.config

I need to rewrite the URL :

http://www.mydomain.com/test.aspx?pagename=quotes&companycode=324543 To http://www.mydomain.com/test/quotes/324543

I am Using IIS 7.5 and VS 2008.

I need the Rule code to written in web.config.

Using the Wizard in the IIS GUI here's the redirect and corresponding rewrite rule. It may not be exactly what you want, but should give you a good idea.

            <rule name="RedirectUserFriendlyURL1" stopProcessing="true">
                <match url="^test\.aspx$" />
                <conditions>
                    <add input="{REQUEST_METHOD}" pattern="^POST$" negate="true" />
                    <add input="{QUERY_STRING}" pattern="^pagename=([^=&amp;]+)&amp;companycode=([^=&amp;]+)$" />
                </conditions>
                <action type="Redirect" url="{C:1}/{C:2}" appendQueryString="false" />
            </rule>
            <rule name="RewriteUserFriendlyURL1" stopProcessing="true">
                <match url="^([^/]+)/([^/]+)/?$" />
                <conditions>
                    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                </conditions>
                <action type="Rewrite" url="test.aspx?pagename={R:1}&amp;companycode={R:2}" />
            </rule>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM