2012-02-03 55 views
0

我正在使用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的目錄部分,而不是查詢字符串部分。問題是,我可以從我的網絡分析工具看到,人們用兩個詞搜索。他們都搜索城市(西雅圖)+類別(餐廳),例如。 「西雅圖餐廳」以及城市(西雅圖)+餐廳名稱(餐廳 - 米開朗基羅)等。 「西雅圖餐廳 - 米開朗基羅」。從結構的角度來看,這當然是一團糟,因爲這不是一個層次結構。在理想的世界裏,等級將是城市 - >類別 - >餐廳。但我仍然希望在我的url結構中適應這種搜索行爲。同時我也有一個列出該國所有餐館的網頁。

我想就如何創建正則表達式以及創建它們的最有效方式提供幫助,因爲我猜它們可能會變得相當昂貴。

感謝

托馬斯

+0

你怎麼一個區分類別和名稱?所有的名字都有破折號或者什麼? – user1096188 2012-02-03 17:40:12

回答

0

使用本:

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

匹配/然後字母,數字1 infininity斜線,線的末端,或者問號

+0

嗯...我無法讓它工作。我沒有那麼多的類別,所以也許我應該做一些類似^〜/(.*)/ restaurant,^〜/(.*)/café等的東西。然後我需要刪除任何查詢字符串(如果它們存在)。那麼不管查詢字符串中的參數數量多少,一個正則表達式如何去除查詢字符串(如果存在的話)?謝謝 – ThomasD 2012-02-03 23:45:26

相關問題