I don’t know much about Apache rewrites and I have this set of requirements that I want to do:
1. http://domain.com/keyword ==> http://domain.com/index.php?c=keyword
2. http://domain.com/keyword?utm_source=affiliate ==> http://domain.com/index.php?c=keyword&utm_source=afiliate
3. Do not rewrite any request like http://domain.com/css/ http://domain.com/images/
I tried to learn and have been able to write a redirect like this for solving #1 and #2:
RewriteEngine on
RewriteRule ^([A-Za-z0-9-+.,]+)\?*(.*)$ index.php?c=$1$2 [QSA]
This does the work for #1 and #2 in my requirements above. However, when I try to access a URL like http://domain.com/b it produces following result in (PHP) $_SERVER['QUERY_STRING']: c=index.php&c=b
Also, I get a continuous loop redirect if I change (just because I was curious) the flag to [R,QSA] with absolute domain, which indicates that the rule is being processed multiple times.
Can someone please help?
Try adding a pair of
RewriteCondto filter those paths you don’t want to be rewrited, like so: