I have a simple database query script alongside with my WordPress installation, to which I pass a parameter using the following URL: http://example.com/db/?p=foo
.
My database script reads the parameter with
$pid = $_GET['p'];
Everthing works fine, IF the parameter does NOT START WITH A NUMBER.
so, ?p=foo
is ok, but ?p=3poo
is EMPTY.
Edit: I confirmed this by changing my script to
<?php
print_r($_GET);
exit;
which gives as an output
Array ( )
I suspect that it's the mod_rewrite who suppresses the parameters starting with a number. But I have no clue why, and how I can change this behavior. Any ideas?
Edit: Unfortunately, I can not change the name of the parameter 'p', nor can I change the values of the parameter so they do not start with numbers, since the URLs where released as QR-tags to the public already, so I need a workaround to make this exact URLs work.
Here is my .htaccess
file in the root folder (edited as suggested by MrWhite, works as expected)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
p
is a query var, it is not safe to use for arbitrary things and carries meaning, and gets passed to the mainWP_Query
, you should avoid it for arbitrary parameters ( and you should look into the REST API, which probably does what your db script is trying to do already )p
. My problem is that I hard printed and distributed already the URLs, so unfortunately can't change, neitherp
, nor the fact that I'm starting with numbers ... thats why I desperately try to find a fix. (if-not, I would just change the parameter values not starting with a number).GET
it should not be an issue, something must be interfering with the$_GET
array, you will need to check your theme and pluginsp
value directly, e.g.var_dump($_GET);exit;
? Have you confirmed this outright? If so edit your question to demonstrate what you did.htaccess
code you posted above doesn't do anything with the query string. Aside: Why have you duplicated the WordPress front-controller? The chunk of code after# BEGIN WordPress
isn't actually doing anything!?