Scott Rushing
Scott Rushing

Reputation: 33

IIS Rewrite rule in web.config

I have the following rule in my web.config file:

<rule name="Reviews SEO Redirect" stopProcessing="true">
<match url="www.mysite.us/reviews/Manufacturer-([^~]*)-([^~]*)-([^~]*)" />
<action type="Redirect" redirectType="Permanent" url="www.mysite.us/reviews/{R:1}" />
</rule>

Now, my goal is to redirect a URL structure like this:

http://www.mysite.us/reviews/Manufacturer-X-Category-Y

to

http://www.mysite.us/reviews/X

If I go to http://www.mysite.us/reviews/X, I get the expected content. if I go to the original URL, it's pulling up the default /reviews VIEW I created in Drupal's View module. And it's not changing the URL in the browser window at all. So it's feeling like it's ignoring the rule or I have the match wrong.

I used a URL rewrite editor to test the rule and it seemed to parse out like I wanted, but when I hit a page on my site with that URL structure, NOTHING happens. So I'm wondering what I've missed.

Any suggestions?

Upvotes: 0

Views: 1880

Answers (1)

beavel
beavel

Reputation: 1087

The match url does not contain the hostname. It should be as follows:

<rule name="Reviews SEO Redirect" stopProcessing="true">
  <match url="reviews/Manufacturer-([^~]*)-([^~]*)-([^~]*)" />
  <action type="Redirect" redirectType="Permanent" url="www.mysite.us/reviews/{R:1}" />
</rule>

This documentation shows how the URL gets broken apart. The problem with the test functionality is that it doesn't trim down the value to what IIS passes in and you end up typing in what you expect. Thus it matches.

Upvotes: 1

Related Questions