Welcome to Vortx Community Forum, where you can ask questions and receive answers from the staff at Vortx and other members of the community.

If you had a user account on our previous forums website, you will need to register a new account here.

Learn more about...

AspDotNetStorefront
DotFeed

Help with 301 redirects / URL rewrite

We're about ready to go live with our ASPDNSF site, and working on 301 redirects to help with the transition from our old asp website. I came across a great article on creating a rewritemap file that can be referenced in web.config to keep it uncluttered. In our case we have several thousand pages that are indexed.

Here's the article: http://www.orcsweb.com/blog/peter/how-to-create-multiple-301-redirects-url-rewrite-map/

The problem is a lot of our indexed urls point to the same page because of some url extensions that we used on the asp pages....like this:

www.domain.com/item.asp?ic=01 and www.domain.com/item.asp?ic=01&agent=google to track traffic

Or www.domain.com/contact.asp and www.domain.com/contact.asp?=CT to manipulate menu behavior

Can someone help with how to add a wildcard to the rewrite map file to allow for these extensions? Simply putting as asterix after contact.asp doesn't work.

<rewriteMaps>
   <rewriteMap name=”Redirects”>
      <add key=”/contact.asp” value=”/t-contact.aspx” /> <!--Need a wildcard after contact.asp-->
   </rewriteMap>
 </rewriteMaps>

asked Oct 15, 2013 in MultiStore by jjones (200 points)
Have you done any custom coding for this so the query strings used in asp pages will mean something to product pages, topics, etc. Reason I ask is there is a high chance the things like products have a differet product ID set than what your asp page/s use.

For example www.domain.com/item.asp?ic=01 may not be same product as www.domain.com/p-1-product-name.aspx
Yes, I'm working on that as well. Will probably do that through an sql query so the product, category and section IDs come out right.

I may have found a solution after a lot of searching. Testing now. If it works, I'll post here for other's benefit.

Was going to suggest trying to making an httpmodule if did end up needing to use a database. http://msdn.microsoft.com/library/ms227673.aspx decent article on how to do so.

The 2nd option that came to mind is since .asp pages can still be scripted to look up the new url ina datase, make copies of the files to redirect to the proper place instead of showing page content.

2 Answers

0 votes

Did you consider our  http://www.ecommercecartmods.com/p-36-301-url-redirect-for-aspdotnetstorefront.aspx  module so you can add these outside of the IIS/web.config?

We do this a lot and can even modify your cart so that the 301 redirects are dynamic and basically use part of the URL requested to find the new page in the new cart and 301 redirect to it...

If you would like a quote, please email me at  jsimacek at compunix.us

answered Oct 16, 2013 by jsimacek (6,765 points)
0 votes

I appreciate the suggestions, and using the 301 url redirect for aspdnsf mod/addon might be the best way to go. However, after some more searching and trial and error, I was able to get it all working--about 10,000 redirects. Here's how it's done in IIS7...

1. Make sure the URL Rewrite Module is installed on your IIS7 server--you can download it from Microsoft.

2. See this article on setting up the redirects and the rewrite map file:

 http://www.orcsweb.com/blog/peter/how-to-create-multiple-301-redirects-url-rewrite-map/

You'll end up with a set of rules for your redirects. Here is one of ours for the category urls

       <rule name="Redirect Category Pages" stopProcessing="true">
        <match url="^items\.asp$" />
        <conditions>
         <add input="{QUERY_STRING}" pattern="cc=([_0-9a-z-]+)" />
         <add input="{CategoriesRedirects:{C:1}}" pattern="(.+)" />
        </conditions>
        <action type="Redirect" url="{C:1}.aspx" appendQueryString="False" redirectType="Permanent" />
       </rule>

This rule takes a url like domain.com/items.asp?Cc=CAT searches the rewrite map file under the name CategoriesRedirects, which looks like this...

<rewriteMap name="CategoriesRedirects" >
  <add key="CAT" value="c-3-cateorgy-name" />
</rewriteMap>

And then permanently redirects to domain.com/c-1-category-name.aspx

This rule also strips additional querystrings/parameters that may be attached to the end of the url, after "CAT" in the example above.

3. Just set up all your rules and make sure each references a unique reWritemap name in the reWrite map file.

4. If you have a lot of redirects, the size of your files may exceed the 256k default limit in IIS7. You'll likely need to increase the default size limit to the web.config in the registry of your server. Here's the MS knowledge base url: http://support.microsoft.com/kb/954864

Add the key HKLM\SOFTWARE\Microsoft\InetStp\Configuration\MaxWebConfigFileSizeInKB (REG_DWORD) and set it to whatever size you need. We used 2048.

A stumper for me, because I'm not a programmer or developer, was how to pass the results of two strings for a redirect. Our old site uses a string for Category and a string for Brand. We've setup sections in ASPDNSF to shop combinations of categories under a certain brand. Here's a copy of a rule that got it done...

<rule name="Redirect Brand Pages" stopProcessing="true">
        <match url="^items\.asp$" />
        <conditions>
         <add input="{QUERY_STRING}" pattern="bc=([_0-9a-z-]+)&amp;cc=([_0-9a-z-]+)" /> <!-- Here are the strings -->
         <add input="{BrandsRedirects:{C:1}{C:2}}" pattern="(.+)" /> 
        </conditions>
        <action type="Redirect" url="{C:1}.aspx" appendQueryString="False" redirectType="Permanent" />
 </rule>

Here's what the reWrite map file entry looks like

<rewriteMap name="BrandsRedirects" >
  <add key="BRANDCAT" value="s-2-section-name" /> <!-- Notice the "key" is a combination of BRAND and CAT from the two strings "bc" and "cc" -->
</rewriteMap>

So this takes the string domain.com/items.asp?Bc=BRAND&Cc=CAT and rewrites to domain.com/s-4-section-name.aspx.

5. Now static redirects. The above addresses the dynamic redirects from your old site, now for static pages. The rule in web.config:

   <rule name="Redirect rule1 for Redirects">
        <match url=".*" />
        <conditions>
         <add input="{Redirects:{REQUEST_URI}}" pattern="(.+)" />
        </conditions>
        <action type="Redirect" url="{C:1}" appendQueryString="false" />
    </rule>

Here's what the reWrite map file entry looks like

 <rewriteMap name="Redirects">
  <add key="/brands.asp" value="/s-1-brand-name.aspx" />
</rewriteMap>

Because we had so many redirects for categories, brands, their combinations and products, I used sql select queries to write keys and values for the map file--joining the tables from ASPDNSF to tables holding the values on the old website.

Maybe it will help some one who is migrating. I'm sure the more experienced can add to or improve this.

answered Oct 17, 2013 by jjones (200 points)
...