使用多个查询字符串重写Mod

时间:2010-06-11 07:02:10

标签: regex mod-rewrite redirect

在正则表达式方面,我是一个完整的n00b。我需要这些重定向:

(1)

www.mysite.com/bike.php?id=001&product=Product-Name&source=Source-Name
should become -> www.mysite.com/Source-Name/001-Product-Name

(2)

www.mysite.com/car.php?id=002&product=Product-Name&source=Source-Name
should become -> www.mysite.com/Source-Name/002-Product-Name

(3)

www.mysite.com/moto.php?id=005&product=Product-Name&source=Source-Name
should become -> www.mysite.com/Source-Name/005-Product-Name

(4)

www.mysite.com/stores.php?id=002&name=Store-Name
should become -> www.mysite.com/002-Store-Name

编辑:我应该澄清,有3个产品页面,应该全部重定向到相同的格式网址

任何帮助非常感谢:)

2 个答案:

答案 0 :(得分:1)

RewriteCond %{REQUEST_URI} www.mysite.com/(.+)/(\d+)-(.+)  /products.php?id=$2&product=$3&source=$1

RewriteCond %{REQUEST_URI} www.mysite.com/(\d+)-(.+)  /products.php?id=$1&name=$2

我认为它运作良好;)

答案 1 :(得分:1)

RewriteEngine On
RewriteRule ^(\d+)-(.+)$ /stores.php?id=$1&name=$2 [L]
RewriteRule ^(.+)/(\d+)-(.+)$ /products.php?id=$2&product=$3&source=$1 [L]