具有相同参数的多个页面的htaccess

时间:2013-07-03 05:55:44

标签: php .htaccess url-rewriting

我有一个问题重写规则。请有人帮助我。我的htaccess代码是

    RewriteEngine On

RewriteCond %{REQUEST_URI} (.*)/(.*)/(.*)/(.*)/(.*)/(.*)/
RewriteRule (.*)/(.*)/(.*)/(.*)/(.*)/(.*)/ /sandbox/all_deals.php?city_id=$1&city_name=$2&cat_id=$3&cat_name=$4&deal_shop_id=$5&deal_shop_name=$6 [L]

RewriteCond %{REQUEST_URI} (.*)/(.*)/(.*)/(.*)/
RewriteRule (.*)/(.*)/(.*)/(.*)/ /sandbox/all_deals.php?city_id=$1&city_name=$2&cat_id=$3&cat_name=$4 

RewriteCond %{REQUEST_URI} (.*)/(.*)/
RewriteRule (.*)/(.*)/ /sandbox/all_deals.php?city_id=$1&city_name=$2 

RewriteCond %{REQUEST_URI} (.*)/(.*)/(.*)/(.*)/(.*)/
RewriteRule (.*)/(.*)/(.*)/(.*)/(.*)/ /sandbox/index.php?p=deals&city_name=$1&shop_name=$2&cat_name=$3&dealname=$4&id=$5

我希望显示如下格式

 1) www.domain.com/sandbox/city-name/shop-name/cat-name/
 2) www.domain.com/sandbox/city-name/shop-name/ 
 3) www.domain.com/sandbox/city-name/
 4) www.domain.com/sandbox/city-name/shop-name/cat-name/deal_name/

在我的编码中,文件名all_deals.php中的前3个点和index.php中的最后一个点。当我使用上面的htaccess我的代码冲突时,它总是重定向到all_deals.php文件。

我将如何解决这些问题。帮我。在此先感谢。

1 个答案:

答案 0 :(得分:0)

你的。*贪婪,/符合你贪婪的正则表达式。 你必须使用lazy regexp。您需要在每个正则表达式的末尾添加?

(.*?)/(.*?)/(.*?)/(.*?)/(.*?)/(.*?)/