除一个参数外,htaccess重写

时间:2014-03-02 15:59:09

标签: .htaccess url-rewriting

我想用htaccess

重写一些网址
http://www.example.com/article.php?post_id=123&title=2014-03-02-today-s-trends
=>
http://www.example.com/article/123/2014-03-02-today-s-trends

但有一些特殊规则。如果某篇文章点击rss或社交分享。我想:

http://www.example.com/article.php?post_id=123&title=2014-03-02-today-s-trends&source=rss
=>
http://www.example.com/article/123/2014-03-02-today-s-trends?source=rss

我的重写代码

RewriteRule ^article/(\d+)/(.*)\?source=(.*)?$ article.php?post_id=$1&title=$2&source=$3

但得到500错误。如何以正确的方式做到这一点?

1 个答案:

答案 0 :(得分:1)

您可以使用QSA标记,以便在网址上显示source=rss时,它会附加查询字符串。

不确定你的ogininal重写是怎么回事,但你可以试试这个。它应该使用或不使用source=rss

RewriteRule ^article/(.+)/(.+)$ article.php?post_id=$1&title=$2 [QSA,L]

然后在您的代码中,您可以检查$ _GET中的source键。