另一个如何识别查询字符串的方法



我正在使用urlrewiting.net进行url重写。我需要一些关于正则表达式的帮助(我仍然没有得到…)。

我想匹配

  • www.mysite.com/restaurant->匹配并返回"restaurant"
  • www.mysite.com/restaurant?page=1->匹配和return"restaurant"
  • www.mysite.com/restaurant?[SOME_RANDOM_QUERYSTRING]->匹配并返回"restaurant"
  • www.mysite.com/seattle/restaurant->匹配并返回"seattle"restaurant"
  • www.mysite.com/seattle/restaurant?page=1->匹配和return"seattle"one_answers"restaurant"
  • www.mysite.com/seattle/restaurant?[SOME_RANDOM_QUERYSTRING]->匹配并返回"seattle"one_answers"restaurant"
  • www.mysite.com/seattle/restaurant-michelangelo->不捕获
  • www.mysite.com/seattle/restaurant/sushi->匹配并返回"seattle"以及"restaurant"one_answers"sushi"
  • www.mysite.com/seattle/restaurant/sushi?page=1->匹配并返回"seattle"one_answers"restaurant"以及"sushi"
  • www.mysite.com/seattle/restaurant/sushi?[SOME_RANDOM_QUERYSTRING]->匹配并返回"seattle"one_answers"restaurant"以及"sushi"
  • www.mysite.com/seattle/restaurant-michelangelo->不捕获

重点是我需要url的目录部分,而不是querystring部分。问题是,我可以从我的网络分析工具中看到,人们通过两个词进行搜索。他们都搜索城市(西雅图)+类别(餐厅),例如"西雅图餐厅",也搜索城市(seattle)+餐厅名称(餐厅米开朗基罗),例如,"西雅图餐厅米开兰基罗"。从结构的角度来看,这当然是一团糟,因为这不是一个等级制度。在理想的世界里,等级制度是城市->类别->餐厅。但我仍然希望在我的url结构中适应这种搜索行为。同时,我还有一个页面列出了全国所有的餐馆。

我想了解如何创建正则表达式以及创建它们的最有效方法,因为我想它们可能会变得非常昂贵。

感谢

Thomas

使用这个:

//[A-Za-z0-9]{1,}(?:/|$|?)/

匹配/字母数字1-中缀,然后斜线、行尾或问号

最新更新