WordPress Won’t Keep My Url Params

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:

Read More

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

Related posts

Leave a Reply

2 comments

  1. 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:

    • Instruct WordPress to save your variables. You add a filter to query_vars to do that. An example is given in the link below.
    • Retrieve your data using $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

  2. Add the “query string append” (QSA) flag to the end of your rewrite rules.

    ‘qsappend|QSA‘ (query string append) This flag forces the rewrite
    engine to append a query string part of the substitution string to the
    existing string, instead of replacing it. Use this when you want to
    add more data to the query string via a rewrite rule.

    RewriteRule . /index.php [L,QSA]
    
    # Without QSA: http://mysite.com/contact-us/?foo=bar →
    #   http://mysite.com/index.php?page_name=contact-us
    # With QSA: http://mysite.com/contact-us/?foo=bar →
    #   http://mysite.com/index.php?page_name=contact-us&foo=bar
    

    See the Apache documentation for more information.