开发者

Wordpress Won't Keep My Url Params

开发者 https://www.devze.com 2023-03-19 21:52 出处:网络
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.

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 p开发者_如何学Carams 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:

  • 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消