Assuming that my website homepage is https://example.com/test-website/
.
What I want to do is to add a query string at the end of the homepage URL and on all pages that start with https://example.com/test-website/products/
and https://example.com/test-website/shop/
.
This is my current code:
# 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
My code works fine and adds the 'loc' query string parameter to the homepage URL and to all pages on wp-admin but it doesn't work on any other pages on the frontend like https://example.com/test-website/products/
. The page just opens normally but without the query string.
I tried to remove the following from my code
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /test-website/index.php [L]
This resulted in making the homepage and wp-admin to still work fine but any other pages on the frontend to give 404 error.
Hope you can help me solve this issue, especially that I don't have experience in regex or mod_rewrite.
/test-website
URL-path segment? Is your.htaccess
file in the document root or in the/test-website
directory?/test-website
directory