0

I've used the .htaccess code in Generic htaccess redirect www to non-www to successfully redirect www.mysite.com to mysite.com, however in the process it strips off the gclid parameter and now AdWords isn't counting clicks correctly.

Is it possible to amend the code below so that any parameters are retained after the redirect?

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
Community
  • 1
  • 1
Andy Groom
  • 619
  • 1
  • 7
  • 15

1 Answers1

0

From: https://wiki.apache.org/httpd/RewriteFlags/QSA

QSA = Query String Append.

This rule appends the GET query string which results from the ReWrite rule to the initial GET query string sent by the browser. For example, take the following RewriteRule:

RewriteRule ^/product/([0-9]*)/?     /product.php?product_id=$1    [QSA]

This simply makes the product_id number look like a directory to the user. Now say that I have two different views of the page, view=short and view=long. For whatever reason, I don't want to make these views look like directories by using a RewriteRule. So I want to be able to do things like:

http://example.com/product/1351283/?view=short

Let's see how QSA works. With QSA, my final rewritten URL is

http://example.com/product.php?product_id=1351283&view=short

QSA has caused the RewriteEngine to append the existing query string (view=short) to the new query string (product_id=1351283). Without QSA, the existing query string is simply replaced by the new query string:

http://example.com/product.php?product_id=1351283

If you do much scripting with reliance on GET variables, it is virtually imperative that you enable the QSA flag on all of your RewriteRules.

Alister Bulman
  • 34,482
  • 9
  • 71
  • 110
  • 2
    This is all well and good, but unless a query string is directly included in the original rewrite, the entire lot will be passed along with the redirect anyway. This is only useful when *adding* query string parameters and wanting to preserve the original ones. – arco444 Dec 16 '14 at 17:05