SiberianGuy
SiberianGuy

Reputation: 25312

ASP.NET MVC Combine two routes into one

Is there any way to combine these two routes strings: {language}/item/{itemId}/proreviews and item/{itemId}/proreviews into one route?

UPD. {language} is optional

UPD2. The workflow is the following: user enters domain.com/item/1/proreviews and I redirect him to the url with the appropriate country code like domain.com/en/item/1/proreviews. Now I am implementing localization and I really don't want to duplicate all my currrent (countrycode-less) routes.

Upvotes: 1

Views: 223

Answers (3)

Dan Atkinson
Dan Atkinson

Reputation: 11699

Why not create a single rewrite rule so that any urls that do not start with a country code in have the language automatically added in (presumably with /en/ in instead).

This way, you will only have one route as IIS will pass the request on to MVC with the language in, and your user will be none the wiser.

This also means that language will be optional.

I should point out though that you should probably 301 these rewrites, otherwise, it's quite likely that you'll suffer SEO consequences as a result of having duplicate content at different urls (/en/item/1234/proreviews will have the same content as /item/1234/proreviews).

Upvotes: 0

Brian
Brian

Reputation: 38025

Routes accept regular expressions. You can come up with a Regular Expression that matches the cultures you support. Just put that route above the default route and it should fall through.

Other possibilities include putting the language in a cookie or perhaps as the subdomain (en.domain.com/item/1/proreviews).

Upvotes: 1

Erik Funkenbusch
Erik Funkenbusch

Reputation: 93444

Why don't you just make {language} the last parameter, then it's easy to make it optional.

Upvotes: 0

Related Questions