Jump to content

Remove query string after logging it.


deansatch

Recommended Posts

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'; ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.