url rewrite using asp.net routers with multiple parameter

为君一笑 提交于 2019-12-13 00:53:56

问题


i am looking for url rewrite options using asp.net routers with multiple parameter. i have parameters of category and location. i need to rewrite url with combination of both category and location or category alone or location alone. how to retrieve the search result based on category,location Example

www.sample.com/flats-for-rent-india
www.sample.com/flats-for-rent
www.sample.com/india

回答1:


This is not possible unless you have unambiguous separator pattern that can delimit category and location. For example, let's say category and location will always be separated by say underscore(_) then you can have two patterns that would do the routing - {term1} or {term1}_{term2}. Again note that I am not saying category or location because term1 or term2 can be either and you have to sniff the actual values for the same.

Most probably, I would go with a single route such as {query} and then have a search algorithm that will search for given query term against both category and location.

If you are probably looking at exact match i.e. {query} should give either location or category or combination then you have to probably implement your search accordingly. For example,

  1. Search the query term against available categories - if match found we are done.
  2. Search the query term against available location - if match found we are done.
  3. Split the query term with possible separators (e.g. hyphen(-), underscore or space) - search parts against category/location. For example, "flats-for-rent-india" would be split into following pairs
    1. flats & for-rent-india
    2. flats-for & rent-india
    3. flats-for-rent & india
      so now you have to try each pair against available categories and locations - this would probably give you a match at #3.


来源:https://stackoverflow.com/questions/9818276/url-rewrite-using-asp-net-routers-with-multiple-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!