重写可能在链接中或可能不在链接中的参数的规则

时间:2014-06-16 04:04:31

标签: php regex apache .htaccess mod-rewrite

我希望能够将这两个地址都用一个规则

twitter/myusername       =>  show.php?acc=twitter&username=myusernbame
twitter/myusername/json  =>  show.php?acc=twitter&username=myusernbame&output=json

这是我到目前为止所写的内容并且它不起作用......事情是第二个参数(json)可能或我不在链接中,因此规则的第二部分应涵盖两者案例

RewriteRule ^twitter/([0-9a-zA-Z]*)(?:/([a-zA-Z]*))$ show.php?acc=twitter&username=$1&output=$2 [L]

1 个答案:

答案 0 :(得分:0)

你的正则表达式似乎不正确,请使用:

RewriteRule ^twitter/([0-9a-zA-Z]+)(?:/([a-zA-Z]+))?/?$ show.php?acc=twitter&username=$1&output=$2 [L,NC,QSA]
相关问题