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
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,
- Search the query term against available categories - if match found we are done.
- Search the query term against available location - if match found we are done.
- 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
- flats & for-rent-india
- flats-for & rent-india
- 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.