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

Cython callback causing memory corruption/segfaults

callback pthreads segmentation-fault cython

I am interfacing python with a c++ library using cython. I need a callback function that the c++ code can call. I also need to pass a reference to a specific python object to this function. This is...

Add web reference during build process

c# .net web-reference

I have a C# solution in Visual Studio 2005. There is a web reference in one project that I have to change when I have to build the project for a determined environment, manually deleting the refere...