[eluser]BradEstey[/eluser]
I need to be able to use Query Strings for 3 things:
- Track is a user came from Google Adwords (looking for $_GET['gclid'])
- Track search queries with Google Analytics (by assigning $_GET['q']
- Our CRM system sends data back to us through the URL.
I've set:
Code:
$config['enable_query_strings'] = TRUE;
But it does nothing. No matter what I try I always get "Undefined index: gclid".
I've narrowed the problem down to my .htaccess file RewriteRule but I don't know how to fix the problem. This is what my .htaccess file looks like:
Code:
RewriteEngine On
RewriteBase /
RewriteCond $1 !^(index\.php|robots\.txt|img/|css/|js/)
RewriteRule ^(.*)$ index.php?/$1 [L]
If I remove the question mark from last line then $_GET['gclid'] works, but if I go to a page like website.com/products?gclid=234234, uri_string() returns "gclid" instead of the actual page URI.
My current solution is just to use
$_SERVER['REQUEST_URI'] instead of
uri_string() and using a simple function to trim off the query strings.
Code:
$end = strrpos($uri, '?');
$uri = substr($uri, 1, ($end-1));
// Returns directory without leading slashes or query strings.
Is there a better solution or should I just stop expecting CI functions to do what $_SERVER variables already exist for?