Developer forum

Forum » Development » Redirecting URLs with URL REWRITE 2.0

Redirecting URLs with URL REWRITE 2.0

Martin Nielsen
Reply

Hey guys,

 

I'm launching a site tomorrow and i need to map about 160 URLs to new locations on the new site.

 

My URLs look like this:

SHOP/Borddaekning.aspx?GroupID=GROUP137&cust_cat=bord#bord
SHOP/Kunst.aspx?GroupID=GROUP290&cust_cat=kunst#kunst
SHOP/Kunst.aspx?GroupID=GROUP287&cust_cat=kunst#kunst
SHOP/Samlet-sortiment.aspx?GroupID=GROUP267&cust_cat=samlet#samlet

SHOP/Samlet-sortiment.aspx?ProductID=PROD777&GroupID=GROUP267&cust_cat=samlet#samlet

 

What i need to do is redirect based on the "GroupID=XXXX" part of the URL.

 

So i want all URL's that container fx. "GroupID=GROUP267" to be redirected the same new URL.

 

I've tried various approached, with both Wildcard and REGEX, but i can get it to work, have you guys tried anything similar?

 

A rule like this doesn't work  with Wildcards: *GroupID=GROUP137*

 

And my attempt at Regex is not worthy of the public :-)

 

 

Hope some off you have had this issue and know what to do :)

 

// Martin

 

 

 

 

 

 

 

 

 

 


Replies

 
Mikkel Ricky
Reply

What about this for a start?

<rewrite>
	<rules>
		<rule name="Rewrite rule" stopProcessing="true">
			<match url=".*" />
			<conditions>
				<add input="{QUERY_STRING}" pattern="GroupID=([^&amp;]+)" />
			</conditions>
			<action type="Redirect" url="/Default.aspx?GroupID={C:1}" appendQueryString="false" logRewrittenUrl="false" redirectType="Permanent" />
		</rule>
	</rules>
</rewrite>

It looks for the GroupID parameter in the query string and redirects if it's found.

Depending on where you are redirecting to, you'll need some tricks to prevent recursively rewriting the urls. 

 

 

 
Martin Nielsen
Reply

Hi Mikkel,

 

Works like a charm, thanks.

 

// Martin

 

You must be logged in to post in the forum