views:

6206

answers:

6

I am a bit stuck on the design of my seo friendly urls for mvc....Take for example the following url: http://myapp/venues/resturants.aspx?location=central&orderBy=top-rated

With my mvc app i have mapped it as follows: http://myapp/venues/list/resturants/central/top-rated
{controller}/{action}/{category}/{location}/{order}

Now the only problem is that location and order are optional...so it should be possible to submit a request like: http://myapp/venues/list/resturants/top-rated . This proves to be a problem when the request hits the controller action, the location parameter has picked up "top-rated", naturally.

Any suggestions? I' am considering using explicit querystrings to handle more than one parameter but this is really my last option as i dont want to sacrifice SEO too much.

Has anyone eles run into such dilemmas? And how did you handle it?

Thanks in advance!

A: 

Why don't you create a property in the page for each possible querystring parameter?

This way you can handle it any way you choose with just a few lines of code...

Sergio
+2  A: 

You will always have this issue if you have multiple optional parameters. Either make one or both of them non-optional (and positioned earlier in the query string than the optional one) or use the querystring parameter notation.

GalacticCowboy
+10  A: 

Click on your profile link and look at the URLs for Stats, Recent, Response, etc.

Examples:

with no sort it defaults to stats

Optional paramters should be query parameters

Todd Smith
+1  A: 

Assuming that the allowed values for location and order are unique (i.e. when they come in, you can tell them apart, or else if they only supply one, how are you going to know if it's a location or an order?), then you could just take two parameters and work out what they are in the controller.

Route: {controller}/{action}/{param1}/{param2}

Controller action:

public ActionResult MyAction(string param1, string param2)
{
    string location;
    string order;
    if (!ParseLocation(param1, out location))
    { ParseLocation(param2, out location); }
    // ...
}

Not particularly elegant, but does let you have the URLs you want.

Giraffe
yep, was exploring this method. I guess i was kinda hoping someone has done something clever with the RouteBase class or something special with the routetables....Thanks alot!
+2  A: 
this is certainly possible, but not a very maintainable long term solution. I'd look into {*pathInfo} as a catchall route parameter and then do the parsing yourself.
Ben Scheirman
A: 

This is something I've been looking into also. I'd like to further ask a question to this actually because it's related, but not necessarily good enough to be a new question.

The navigation system we currently use at work is cross-compatible, so files in one menu system hook into another. We use frames to make this easier but obviously they're outdated by a long-shot and should've been deprecated years ago.

So we have two frames, the left is the navigation, the right is the content. On the left there may be a link to a file which is in a completely different directory, so using URL rewrites like this wouldn't work - or would they? Any ideas?

Kezzer