vote up 3 vote down
star
1

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!

flag
add comment

6 Answers:

vote up 0 vote down
check

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.

link|flag
comments (1)
vote up 3 vote down

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

link|flag
add comment
vote up 2 vote down

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.

link|flag
add comment
vote up 2 vote down

ok guys just posting a solution i've been playing with so far.

I have set up my routes using constraints as follows:



        routes.MapRoute(
            "VenuesList",                                              
            "venues/list/{category}/{location}/{orderBy}",             
            new { controller = "venues", action = "list", category = "", location = "", orderBy = "" },
            new { location = "central|east|west|south", orderBy = "top-rated|price" }
        );

    routes.MapRoute(
            "VenuesListByLocation",                                              
            "venues/list/{category}/{location}",                           
            new { controller = "venues", action = "list", category = "", location = "" },
            new { location = "central|east|west|south" }
        );

        routes.MapRoute(
            "VenuesListByOrder",                                              
            "venues/list/{category}/{orderBy}",                           
            new { controller = "venues", action = "list", category = "", orderBy = "" },
            new { orderBy = "top-rated|price" }
        );

        routes.MapRoute(
            "VenuesListDefault",                                              
            "venues/list/{category}",                           
            new { controller = "venues", action = "list", category = "" }

        );

        routes.MapRoute(
            "Default",                                              
            "{controller}/{action}/{id}",                           
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

The idea is that if the validation fails it will go to the next route in the list...eventually hitting the default.

Needs some more testing but has worked well so far...

link|flag
comments (1)
vote up 0 vote down

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?

link|flag
add comment
vote up 0 vote down

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...

link|flag
add comment

Your Answer:

Get an OpenID
or

Not the answer you're looking for? Browse other questions tagged or ask your own question.