I just changed t开发者_如何转开发he 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.
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.
精彩评论