I’m working on WP website and anytime I add url params to the url, it redirects the page to a version without the params.
Example:
http://mysite.com/?foo=bar -> redirects to -> http://mysite.com/
http://mysite.com/contact-us/?foo=bar -> redirects to http://mysite.com/contact-us/
How can I fix this? We need certain params to load with the page for various reasons.
Contents of .htaccess (edited to add QSA – which isn’t working):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L,QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L,QSA]
</IfModule>
# END WordPress
You have to use
query_vars
to make that happen. WordPress stores all the query string parameters that it may need in a global object and it ignores everything else.You need to instruct it to do the following:
query_vars
to do that. An example is given in the link below.$wp_query->query_vars['customvariable']
instead of the regular_GET
or_POST
.The details can be found here: http://codex.wordpress.org/Custom_Queries#Custom_Archives
Add the “query string append” (
QSA
) flag to the end of your rewrite rules.See the Apache documentation for more information.