ASP.Net 301 redirects and URL rewriting

I just changed the structure of page urls of one of my websites using URL rewriting and I need to redirect the old structure to the new one (to handle old links indexed by Google). My problem is that I want to redirect to a rewritten URL, not an actual URL and I cannot find a way to do this.

Before the changes I had the following urls:

RewriteRule ^products/([^_\r\n//]*)/([^_\r\n//]*)/$ /products.aspx?cat=$1&subcat=$2 [NC,L]

After the changes, I have the following:

RewriteRule ^products-([^_\r\n//]*)-([^_\r\n//]*)/$ /products.aspx?cat=$1&subcat=$2 [NC,L]

What I want to do now is issue a 301 redirect for urls that match

^products/([^_\r\n//]*)/([^_\r\n//]*)/$ to ^products-([^_\r\n//]*)-([^_\r\n//]*)/$,

ie, to have the following rule:

RewriteRule ^products-([^_\r\n//]*)-([^_\r\n//]*)/$ products-([^_\r\n//]*)-([^_\r\n//]*)/ [NC,L]

The above rule produces the following error:

"The page isn't redirecting properly"

Is there a way to do it with .Net or using Url rewrite rules?

Any help would be grately appreciated.

Answers


Ok, I fixed the problem using the following rule:

RewriteRule ^products-([^_\r\n//]*)-([^_\r\n//]*)/$ /redir.aspx?url=/products-$1-$2/ [NC,L]

What the redir.aspx page does is write a 301 code to the header and transfer to the new url that is passed as a parameter to it.


Need Your Help

Javascript sort help

javascript sorting

I'm trying to sort some xml into different arrays and I'm a bit stuck on how to go about this.

Eclipse 'Add CVS Repository' hangs on known-good settings

eclipse eclipse-plugin ssh cvs

I have a CVS server which is known to be ok (works from other machines).

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.