For testing purposes, I would like to append a query string (let’s say testing=true) to any url requested from my website.

For testing purposes, I would like to append a query string (let's say testing=true) to any url requested from my website.

#E.g. I want to change

example.com
example.com/product
example.com/search?q=string

to

example.com?testing=true

example.com/product?testing=true

example.com/search?q=string&testing=true



Answer:

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond %{QUERY_STRING} !(^|&)testing=true(&|$) [NC]

    RewriteRule ^ %{REQUEST_URI}?testing=true [L,QSA,R]

    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)

    RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

Leave a Reply

Your email address will not be published. Required fields are marked *