Reputation: 1
I do not understand very much about IIS but I am trying to do a redirect with URL rewriting. I am trying to do a redirect from http://www.cooltoys.com.au/besttoys to http://www.cooltoys.com.au/bestcooltoys
I have got the following code in my Web.config file and it doesn't work and i'm having difficulty understanding why.
<rules>
<rule name = "ToysRedirect" StopProcessing="true" />
<match url = "besttoys" />
<action type = "Redirect" url = "http://www.cooltoys.com.au/bestcooltoys" appendQueryString="true" redirectType="Permanent"/>
</rule>
</rules>
I think the problem is in the "match url" part (Pattern) so can someone please explain how to write this so it redirects correctly. Thanks, Corey
Upvotes: 0
Views: 51
Reputation: 3952
It will be something like:
<rules>
<rule name = "ToysRedirect" StopProcessing="true" />
<match url = "^(.*)/besttoys$" />
<action type = "Redirect" url = "{R:1}/bestcooltoys" appendQueryString="true" redirectType="Permanent"/>
</rule>
Basically you need to learn regular expressions. "^(.*)/besttoys$" - means that the we look for any url that will end with /besttoys and then we replace it with /bestcooltoys. The () chars define a group which we can then refer to by {R:1} - means first defined group.
Upvotes: 1