0

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

2
  • I know this doesn't specifically answer your question but this might help you a little more going forward amazon.co.uk/Learn-Windows-IIS-Month-Lunches/dp/1617290971 Commented Feb 24, 2016 at 10:51
  • 1
    Also please dont flag this as already answered, I am aware of the other similar questions but they did not help with my problem Commented Feb 24, 2016 at 10:52

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.