2011-12-08 25 views
1

我需要重写使用htaccess的规则重写规则,我现在有以下几点:需要各种查询字符串组合

RewriteRule ^test/example/(.*)/(.*)/(.*)/example\.html$ test/example/example/index.php?s=$1&t=$2&p=$3 [L] 

其rewites从URL:

测试/示例/实施例/索引。 PHP?S =红色&吨=奥迪& p =汽油

测试/示例/红/奥迪/汽油/ example.html的

这个工作,但我想规则为以下3个条件的工作:

  1. 在没有值的查询字符串所以才去的网址:测试/例子/ example.html的

  2. 其中 “s” 在查询字符串具有一个值,然后重写规则发送用户:测试/示例/红/ example.html的

  1. 所有三个瓦尔有值,然后链接进入:测试/例子/红/奥迪/汽油/ example.html的

感谢

回答

2

顺序添加三个重写规则:

RewriteRule ^test/example/(.*)/(.*)/(.*)/example\.html$ test/example/example/index.php?s=Red&t=Audit&p=Petrol 
RewriteRule ^test/example/(.*)/example\.html$ test/example/example.html?s=Red 
RewriteRule ^test/example/example\.html$ test/example/example.html 

而且都完成了。

+1

你对正则表达式有什么耐心吗? :P很好。 – phpmeh

+0

我写的编译器为生:)所有正则表达式都是私人朋友 –

+0

谢谢,我应该猜到了! :) – Dino