0

I have a really odd issue:

  1. I have a WP site, staging and live are on the same server.
  2. Query string variables aren't registering in the $_GET or $_REQUEST arrays on the live site (but they are on staging). Code in the same place, where QS vars are needed, dumping $_REQUEST, gives the vars as expected on staging, but an empty array on live.
  3. If I dump $_REQUEST in a standalone test.php file, it works in both sites in terms of QS vars being registered.
  4. If I dump $_REQUEST at the top of WP's index.php, it works on staging, but on live I only see cookie data.

The codebase is the same, same WP version, same plugins, same plugin versions. Obviously something is different! But I'm stuck as to how to do more to track this down. I'm not sure what could be making the difference between something processed in test.php and something at the top of index.php. Any ideas?

  • I'd get in touch with my hosting provider in such a case following your statement "The codebase is the same, same WP version, same plugins, same plugin versions. Obviously something is different" – Ahmed Fouad Sep 27 '16 at 13:00
  • Are the web configurations the same? .htaccess files, vhost configurations, etc.? Certain rewrite directive flags and/or modifications will drop querystrings. This could account for your standalone test.php functioning as expected if it's URL is left untouched. Could you post the live site's .htaccess? – bosco Sep 27 '16 at 22:00
1

Missing GET request variables are sometimes a symptom of improper rewrite rules in the web-server's configuration files. In the case of Apache, rewrites are most often implemented using the mod_rewrite module's directives in the WordPress installation's directory-level .htaccess configuration file - however, a faulty rewrite rule could also be present in higher-level configuration files (directory, vhost, primary configuration, etc.).

By default, WordPress routes every request for anything except existing files and directories to index.php using a configuration similar to the following:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

There are two modifications that will cause these directives to drop the querystring in the process of rewriting the request:

  • The discard querystring flag. This is added to the square brackets at the end of a RewriteRule directive as either QSD or qsdiscard. If this flag is present for either of the RewriteRule directives in the configuration above, the querystring will be discarded for virtually every request handled by WordPress. For example:

    RewriteRule ^index\.php$ - [L,QSD]
    
  • Any use of a ? in a RewriteRule directive's substitution string (without the append querystring flag). Specifying any querystring (even a single ? without any subsequent key/value pairs) in the substitution will result in the rewrite completely replacing the original querystring. For example:

    RewriteRule . /index.php? [L]
    

    or

    RewriteRule . /index.php?foo=bar [L]
    

    If it is desireable to append a custom GET variable to every rewrite, the append querystring flag can be specified in the brackets as QSA or qsappend in order to merge the querystring in the substitution with the original querystring instead of completely overwriting it:

    RewriteRule . /index.php?foo=bar [L,QSA]
    
  • Many thanks, this sounds like it could be in the right direction. The real issue here is that the exact same .htaccess file is being used on staging, on the same server, which works fine. There are a lot of Redirect directives, but the only RewriteRules are the standard WP code (exactly as above), and a no-www redirect (see pastebin.com/EtFt7MFx). I'll contact the server admins to see if there's any global directives. – Steve Taylor Sep 27 '16 at 22:59
  • I thought I might be able to temporarily fix this by change the form in question to POST rather then GET (it's a form which applies filters - e.g. year, author - to a list of blog posts). However, the problem persist. It's evidently not just GET vars that are being wiped, but POST vars too. – Steve Taylor Sep 27 '16 at 23:16
  • Your .htaccess definitely looks alright (although you might want to add RewriteEngine On and RewriteBase / to the top of your www-redirect - it may not matter in your host environment, though). Taking into account that it's discarding POST data as well, it sounds like it might be a PHP configuration issue - but I take it both sites probably use the same PHP configuration as well? – bosco Sep 27 '16 at 23:28
  • That's not the full file, just the bits with RewriteRule. I'll check PHP config. – Steve Taylor Sep 28 '16 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.