Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello everybody!

How to implement URL redirection in ASP.NET MVC 2 from all pages which start from 'http://www.website.com/products/brand1' to 'http://www.website.com/products/brand2'? Here 'brand1' and 'brand2' are parameters. I know how to do it writing code in controllers but I have a lot of them in 'Products' area therefore I need more efficient way.

This is an existing site.
Really I have one area 'Products' where I have several brands with the same functionality. So I have the following links:
http://www.website.com/products/adidas/addnewproduct
http://www.website.com/products/adidas/editproduct?id=345
http://www.website.com/products/adidas/admin/index
...
http://www.website.com/products/nike/addnewproduct
http://www.website.com/products/nike/editproduct?id=345
http://www.website.com/products/nike/admin/index

And now I want to redirect from 'adidas' to 'adidas_new'. It means when the user types 'http://www.website.com/products/adidas/addnewproduct' in browser it redirects to 'http://www.website.com/products/adidas_new/addnewproduct'


Thanks in advance.
Posted
Updated 30-Jan-12 23:35pm
v2

Hi,

Instead of creating a different view like 'http://www.website.com/products/brand1' or 'http://www.website.com/products/brand2' you can create a single view something like http://www.website.com/products/brand?id=1 and pass the 'brandid' as paramater in query strinf, you can handle the query string parameters in your controller.

I hope i answered you question here.
 
Share this answer
 
Comments
Pavel Yermalovich 31-Jan-12 5:28am    
This is an existing site and I cannot change url schema as you offer.
Really I have one area 'Products' where I have several brands with the same functionality. So I have the following links:
http://www.website.com/products/adidas/addnewproduct
http://www.website.com/products/adidas/editproduct?id=345
http://www.website.com/products/adidas/admin/index
...
http://www.website.com/products/nike/addnewproduct
http://www.website.com/products/nike/editproduct?id=345
http://www.website.com/products/nike/admin/index

And now I want to redirect from 'adidas' to 'adidas_new'. It means when the user types 'http://www.website.com/products/adidas/addnewproduct' in browser it redirects to 'http://www.website.com/products/adidas_new/addnewproduct'
sujit0761 16-Feb-12 1:55am    
In you global.asax file in the application_start function you can use

Response.RedirectPermanent(). You can check the url if its 'http://www.website.com/products/adidas/addnewproduct' you can redirect it to 'http://www.website.com/products/adidas_new/addnewproduct' using Response.RedirectPermanent(). This would create a 302 response status which would help the search engines to update their tabls also.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900