【发布时间】:2012-02-04 02:56:16
【问题描述】:
我正在使用 urlrewriting.net 进行 urlrewriting。我需要一些关于正则表达式的帮助(我仍然没有得到......)。
我想匹配
-
www.mysite.com/restaurant-> 匹配并返回 "restaurant" -
www.mysite.com/restaurant?page=1-> 匹配和 返回“restaurant” -
www.mysite.com/restaurant?[SOME_RANDOM_QUERYSTRING]-> 匹配 并返回“restaurant” -
www.mysite.com/seattle/restaurant-> 匹配并返回“seattle”和 "restaurant" -
www.mysite.com/seattle/restaurant?page=1-> 匹配和 返回“seattle”和“restaurant” -
www.mysite.com/seattle/restaurant?[SOME_RANDOM_QUERYSTRING]-> 匹配 并返回“seattle”和“restaurant” -
www.mysite.com/seattle/restaurant-michelangelo-> 不要抓到 -
www.mysite.com/seattle/restaurant/sushi-> 匹配并返回“seattle” 和“restaurant”和“sushi” -
www.mysite.com/seattle/restaurant/sushi?page=1-> 匹配并返回 “seattle”和“restaurant”和“sushi” -
www.mysite.com/seattle/restaurant/sushi?[SOME_RANDOM_QUERYSTRING]-> 匹配并返回“seattle”和“restaurant”和“sushi” -
www.mysite.com/seattle/restaurant-michelangelo-> 不要抓到
关键是我需要 url 的目录部分而不是查询字符串部分。问题是我可以从我的网络分析工具中看到,人们用两个词进行搜索。他们都搜索城市(西雅图)+类别(餐厅),例如。 “西雅图餐厅”,也适用于城市 (seattle) + 餐厅名称 (restaurant-michelangelo),例如。 “西雅图餐厅-米开朗基罗”。从结构的角度来看,这当然是一团糟,因为这不是层次结构。在理想的世界中,层次结构是城市 -> 类别 -> 餐厅。但我仍然想在我的 url 结构中适应这种搜索行为。同时我也有一个页面列出了全国所有的餐馆。
我想获得有关如何创建正则表达式以及创建它们的最有效方法的帮助,因为我猜它们可能会变得非常昂贵。
谢谢
托马斯
【问题讨论】:
-
您如何区分类别和名称?所有的名字都有破折号还是什么?
标签: regex url-rewriting regex-greedy urlrewriting.net