Question

I want to make some url rewrite with 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

but some special rule. if some article click from rss or social share. I want to:

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

my rewrite code here

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

but get 500 error. How to do it in a right way?

Was it helpful?

Solution

You can just use the QSA flag so that it will append the query string with it if source=rss is on the URL.

Not sure how your ogininal rewrite is but you can try this. It should work with or without source=rss

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

Then in your code you can check for the source key in the $_GET.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top