2013-04-15 36 views
0

我的.htaccess是看起來像這樣:如何通過'RewriteCond'來簡化.htaccess重寫?

#01 
RewriteRule ^([a-z]+)/yule/*$ index.php?city=$1&category=2 

RewriteRule ^([a-z]+)/yule/today/*$ index.php?city=$1&category=2&today=true 
RewriteRule ^([a-z]+)/yule/today/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=2&today=true&order=$2&ordertype=$3 
RewriteRule ^([a-z]+)/yule/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=2&order=$2&ordertype=$3 

RewriteRule ^([a-z]+)/yule_([0-9]+)-([0-9]+)?/*$ index.php?city=$1&category=2&price_sta=$2&price_end=$3 
RewriteRule ^([a-z]+)/yule_([0-9]+)-([0-9]+)?/today/*$ index.php?city=$1&category=2&price_sta=$2&price_end=$3&today=true 
RewriteRule ^([a-z]+)/yule_([0-9]+)-([0-9]+)?/today/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=2&price_sta=$2&price_end=$3&today=true&order=$4&ordertype=$5 
RewriteRule ^([a-z]+)/yule_([0-9]+)-([0-9]+)?/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=2&price_sta=$2&price_end=$3&order=$4&ordertype=$5 

#02 
RewriteRule ^([a-z]+)/travel/*$ index.php?city=$1&category=3 

RewriteRule ^([a-z]+)/travel/today/*$ index.php?city=$1&category=3&today=true 
RewriteRule ^([a-z]+)/travel/today/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=3&today=true&order=$2&ordertype=$3 
RewriteRule ^([a-z]+)/travel/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=3&order=$2&ordertype=$3 

RewriteRule ^([a-z]+)/travel_([0-9]+)-([0-9]+)?/*$ index.php?city=$1&category=3&price_sta=$2&price_end=$3 
RewriteRule ^([a-z]+)/travel_([0-9]+)-([0-9]+)?/today/*$ index.php?city=$1&category=3&price_sta=$2&price_end=$3&today=true 
RewriteRule ^([a-z]+)/travel_([0-9]+)-([0-9]+)?/today/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=3&price_sta=$2&price_end=$3&today=true&order=$4&ordertype=$5 
RewriteRule ^([a-z]+)/travel_([0-9]+)-([0-9]+)?/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=3&price_sta=$2&price_end=$3&order=$4&ordertype=$5 

#03 
RewriteRule ^([a-z]+)/service/*$ index.php?city=$1&category=4 

RewriteRule ^([a-z]+)/service/today/*$ index.php?city=$1&category=4&today=true 
RewriteRule ^([a-z]+)/service/today/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=4&today=true&order=$2&ordertype=$3 
RewriteRule ^([a-z]+)/service/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=4&order=$2&ordertype=$3 

RewriteRule ^([a-z]+)/service_([0-9]+)-([0-9]+)?/*$ index.php?city=$1&category=4&price_sta=$2&price_end=$3 
RewriteRule ^([a-z]+)/service_([0-9]+)-([0-9]+)?/today/*$ index.php?city=$1&category=4&price_sta=$2&price_end=$3&today=true 
RewriteRule ^([a-z]+)/service_([0-9]+)-([0-9]+)?/today/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=4&price_sta=$2&price_end=$3&today=true&order=$4&ordertype=$5 
RewriteRule ^([a-z]+)/service_([0-9]+)-([0-9]+)?/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=4&price_sta=$2&price_end=$3&order=$4&ordertype=$5 

#04 
RewriteRule ^([a-z]+)/gou/*$ index.php?city=$1&category=5 

RewriteRule ^([a-z]+)/gou/today/*$ index.php?city=$1&category=5&today=true 
RewriteRule ^([a-z]+)/gou/today/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=5&today=true&order=$2&ordertype=$3 
RewriteRule ^([a-z]+)/gou/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=5&order=$2&ordertype=$3 

RewriteRule ^([a-z]+)/gou_([0-9]+)-([0-9]+)?/*$ index.php?city=$1&category=5&price_sta=$2&price_end=$3 
RewriteRule ^([a-z]+)/gou_([0-9]+)-([0-9]+)?/today/*$ index.php?city=$1&category=5&price_sta=$2&price_end=$3&today=true 
RewriteRule ^([a-z]+)/gou_([0-9]+)-([0-9]+)?/today/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=5&price_sta=$2&price_end=$3&today=true&order=$4&ordertype=$5 
RewriteRule ^([a-z]+)/gou_([0-9]+)-([0-9]+)?/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=5&price_sta=$2&price_end=$3&order=$4&ordertype=$5 

#05 
RewriteRule ^([a-z]+)/qita/*$ index.php?city=$1&category=6 

RewriteRule ^([a-z]+)/qita/today/*$ index.php?city=$1&category=6&today=true 
RewriteRule ^([a-z]+)/qita/today/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=6&today=true&order=$2&ordertype=$3 
RewriteRule ^([a-z]+)/qita/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=6&order=$2&ordertype=$3 

RewriteRule ^([a-z]+)/qita_([0-9]+)-([0-9]+)?/*$ index.php?city=$1&category=6&price_sta=$2&price_end=$3 
RewriteRule ^([a-z]+)/qita_([0-9]+)-([0-9]+)?/today/*$ index.php?city=$1&category=6&price_sta=$2&price_end=$3&today=true 
RewriteRule ^([a-z]+)/qita_([0-9]+)-([0-9]+)?/today/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=6&price_sta=$2&price_end=$3&today=true&order=$4&ordertype=$5 
RewriteRule ^([a-z]+)/qita_([0-9]+)-([0-9]+)?/(price|rebate|bought)_(desc|asc)/ index.php?city=$1&category=6&price_sta=$2&price_end=$3&order=$4&ordertype=$5 

#06 
#07 
#08 
... ... 

我有很多類,如: '尤爾', '旅行', '服務', '苟', 'qita',很多~~~~ categorys ~~~~~~這些類別對應於這樣的id:'meishi' - > category = 1'yule' - > category = 2'travel' - > category = 3'service' - > category = 4'gou' - > category = 5'qita' - > category = 6 ~~~~~~~如何簡化這些分類使用'RewriteCond'?

+0

我認爲你正在尋找RewriteMap,其中規則將獲取提供的ID的url-slug。我對嗎? –

+0

我沒有寫RewriteMap的經驗。 – leondaa

回答

1

看一看有關重寫映射文檔:

你這裏的目標是將人類可讀的蛞蝓類映射到一個類別編號,通過文本文件的方式。

例如,如果你輸入/travel爲您的網址,映射器會諮詢文本文件,並返回3該類別

所以,([a-z]+)/([a-z]+)將成爲index.php?city=$1&category=${examplemap:$1|/404.php}。 例如,在查找/映射之後,mycity/travel將變爲index.php?city=mycity&category=3

然後,用你的重寫規則,你就不需要重複所有的人都爲每個類別。

如果您有文檔的困難,讓我知道,我會盡量把東西一起給你。

+0

謝謝,我試了一下。 – leondaa