Deckerz Deckerz - 2 months ago 26
Apache Configuration Question

Remove ?gclim=<random_code> using .htaccess

I have this .htaccess

RewriteEngine On
Options -Indexes
Options +FollowSymLinks

RewriteCond %{HTTP_HOST} !^www.****.com$
RewriteRule ^(.*)$ http://www.****.com/$1 [L,R=301]

RewriteCond $1 !^(index\.php|media|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]

ErrorDocument 404 /page-not-found


And when google ads navigate to it because of the codeigniter setup it causes a 404, i need to remove the gclim from the URL completely.

How can i do that with pure .htaccess

Answer

I need to remove the gclim from the URL completely.

You can insert this redirect rule just below 2nd Options line:

ErrorDocument 404 /page-not-found
Options +FollowSymLinks -Indexes

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?gclim=[^&]*(?:&(.*))?$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [L,R=301,NE]

RewriteCond %{HTTP_HOST} !^www.****.com$
RewriteRule ^(.*)$ http://www.****.com/$1 [L,R=301]

RewriteCond $1 !^(index\.php|media|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]