2013-04-15 3 views
0

мой .htaccess это выглядит следующим образом:Как упростить .htaccess Rewriterule от 'RewriteCond'?

#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, где правило будет извлекать URL-адрес для предоставленного ID. Я прав? –

+0

У меня нет опыта написания RewriteMap. – leondaa

ответ

1

Посмотрите на документы о Rewrite Mapping:

Ваша цель здесь заключается в карту удобочитаемый категории слизняка к категории числа, с помощью текстового файла.

Например, если вы были ввести /travel как ваш URL, картограф проконсультирует текстовый файл и вернуть 3 для категории

Так, ([a-z]+)/([a-z]+) станет index.php?city=$1&category=${examplemap:$1|/404.php}. Например, mycity/travel станет index.php?city=mycity&category=3 после поиска/карты.

Затем, используя правила перезаписи, вам не нужно будет повторять их все для каждой категории.

Если у вас возникли трудности с документацией, дайте мне знать, и я постараюсь собрать что-то вместе для вас.

+0

Спасибо, я попробую. – leondaa

Смежные вопросы