Savaş Zorlu
Savaş Zorlu

Reputation: 91

url rewrite rule to parse url dynamically

I am using rewrite map method to achive my seo friendly urls.

        <rewriteMaps>
            <rewriteMap name="Destinations">
                <add key="/point-a-to-point-b" value="/destination-final.asp?from=point%20a&amp;to=point%20b" />
            </rewriteMap>   
        </rewriteMaps>
            <rules>
            <rule name="Rewrite rule1 for Destinations">
                <match url=".*" />
                <conditions>
                    <add input="{Destinations:{REQUEST_URI}}" pattern="(.+)" />
                </conditions>
                <action type="Rewrite" url="{C:1}" appendQueryString="false" />
            </rule> 
        </rules>

My problem is I have too many destinations and having to write a map for each results in 500 error. I believe there is a limit to the number of maps you can have on single web.config file.

would it be possible to achive this using a wildcard rule?

that would parse the url and use the bit before "to" as starting point and the bit after "to" as end point and send it to the file as querystring?

for example

/newyork-to-texas

would send the following querystring:

from=newyork&to=texas

Upvotes: 0

Views: 499

Answers (1)

Jalpa Panchal
Jalpa Panchal

Reputation: 12769

Could you please share a detailed error message for 500 error. if you want to achieve your requirement /newyork-to-texas to from=newyork&to=texas you could use below url rewrite rule:

<rule name="send value to query string" enabled="true" stopProcessing="true">
                <match url="(.*)" />
                <conditions>
                    <add input="{REQUEST_URI}" pattern="(.*)/(.*)\-to\-(.*)" />
                </conditions>
                <action type="Redirect" url="http://localhost:746/default.aspx?from={C:2}&amp;to={C:3}" appendQueryString="false" />
            </rule>

enter image description here

Regards, Jalpa.

Upvotes: 1

Related Questions