I have a geoip http header named {HTTP:CF-IPCountry} that store the country code like FR, US etc.. what i need to do is to add this query string loc={HTTP:CF-IPCountry} to the website homepage https://example.com/test-website/ and to any page that has url start with https://example.com/test-website/products/ or https://example.com/test-website/shop/ and append the query string if there are any other query strings used on the url so if the user requested page https://example.com/test-website/products/shoe/?size=s it should rewrited as https://example.com/test-website/products/shoe/?size=s&loc=us
This is how htaccess file looks like curently
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test-website/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /test-website/index.php [L]
RewriteCond %{REQUEST_METHOD} !^POST
RewriteCond %{QUERY_STRING} !^loc [NC]
RewriteRule (.*) /%{REQUEST_URI}/?loc=%{HTTP:CF-IPCountry} [NC,NE,R,L,QSA]
</IfModule>
# END WordPress
The issue i have at the moment is that the rewrite rule works only on the website homepage https://example.com/test-website/ and the website admin panel pages https://example.com/test-website/wp-admin but it doesn't work with any other pages on the frontend like https://example.com/test-website/products/
Hope you can answer my question as simply as posible especially that i dont have any experiance with rewriteRules.
Thanks