deansatch Posted January 20, 2010 Share Posted January 20, 2010 I have added a little query string to some of my links for tracking e.g. mysite.com/page2.php?track1 For fear of damaging SEO and for vanity, I want that query string to disappear when the user lands on the page. BUT, I want to echo the query string on that page. (don't ask why) I tried using a rewrite in htaccess: RewriteCond %{QUERY_STRING} . RewriteRule ^(.*)page2.php$ http://mysite.com/page2.php$1? [R=301,L] This removes it fine but it doesn't echo it out since it removes it before it gets to: echo $_SERVER["QUERY_STRING"]; Is there any way to achieve this without affecting my usually 'un-query_stringed' urls with regards to SEO? Quote Link to comment https://forums.phpfreaks.com/topic/189199-remove-query-string-after-logging-it/ Share on other sites More sharing options...
schilly Posted January 20, 2010 Share Posted January 20, 2010 use php and add it to the user's session then redirect them? Quote Link to comment https://forums.phpfreaks.com/topic/189199-remove-query-string-after-logging-it/#findComment-998909 Share on other sites More sharing options...
deansatch Posted January 21, 2010 Author Share Posted January 21, 2010 Would that not affect my internal link SEO in a negative way though? Quote Link to comment https://forums.phpfreaks.com/topic/189199-remove-query-string-after-logging-it/#findComment-999347 Share on other sites More sharing options...
roopurt18 Posted January 21, 2010 Share Posted January 21, 2010 Why use the query string for tracking at all? Why not just store the value in the user's session. Quote Link to comment https://forums.phpfreaks.com/topic/189199-remove-query-string-after-logging-it/#findComment-999390 Share on other sites More sharing options...
deansatch Posted January 21, 2010 Author Share Posted January 21, 2010 Why use the query string for tracking at all? Why not just store the value in the user's session. Because I am trying to see which link was clicked on on a page which may have a few different links to the same page e.g. click here, sign up, and an image - I want to know which one is clicked on. Quote Link to comment https://forums.phpfreaks.com/topic/189199-remove-query-string-after-logging-it/#findComment-999395 Share on other sites More sharing options...
roopurt18 Posted January 21, 2010 Share Posted January 21, 2010 $_SERVER['HTTP_REFERER'] Quote Link to comment https://forums.phpfreaks.com/topic/189199-remove-query-string-after-logging-it/#findComment-999493 Share on other sites More sharing options...
schilly Posted January 21, 2010 Share Posted January 21, 2010 $_SERVER['HTTP_REFERER'] +1 Quote Link to comment https://forums.phpfreaks.com/topic/189199-remove-query-string-after-logging-it/#findComment-999498 Share on other sites More sharing options...
deansatch Posted January 21, 2010 Author Share Posted January 21, 2010 That will only tell me which page I am coming from, not which link I used. I would still need the query string Quote Link to comment https://forums.phpfreaks.com/topic/189199-remove-query-string-after-logging-it/#findComment-999506 Share on other sites More sharing options...
crabfinger Posted January 21, 2010 Share Posted January 21, 2010 this is my .htaccess file RewriteEngine on RewriteCond %{REQUEST_URI} !=/index.php RewriteRule ^(.+?)\.php$ index.php?page=$1 [QSA] so http://www.example.com/hello-world.php?say=something http://www.example.com/example/hello-world.php?say=something http://www.example.com/index.php?page=hello-world&say=something Turns into http://www.example.com/index.php?page=hello-world&say=something http://www.example.com/index.php?page=example/hello-world&say=something http://www.example.com/index.php?page=hello-world&say=something Quote Link to comment https://forums.phpfreaks.com/topic/189199-remove-query-string-after-logging-it/#findComment-999510 Share on other sites More sharing options...
roopurt18 Posted January 21, 2010 Share Posted January 21, 2010 Apparently 2 1/2 cups of coffee is not enough for me today because I'm making bad suggestions. Instead of: mysite.com/page2.php?track1 Create the URL as: mysite.com/track1/page2.php Then you can use this as a rewrite: RewriteCond %{REQUEST_URI} /track[^/]+/.* RewriteRule /(track[^/]+)/(.*) /$2?__track=$1 [QSA,L] Then in the page, you should be able to use: <?php echo array_key_exists( '__track', $_GET ) ? $_GET['__track'] : 'Tracking not set'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/189199-remove-query-string-after-logging-it/#findComment-999523 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.