0

我有一个问题重写规则。请有人帮助我。我的 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 文件。

我将如何解决这些问题。帮我。提前致谢。

4

1 回答 1

0

你的 .* 是贪婪的并且/匹配你贪婪的正则表达式。您必须改用惰性正则表达式。您需要?在每个正则表达式的末尾添加:

(.*?)/(.*?)/(.*?)/(.*?)/(.*?)/(.*?)/
于 2013-07-03T06:09:35.717 回答