I have a PHP page with querystring:
http://project.dev/?a=b&c=d
As you know, I can access the querystring with $_GET superglobal array:
print_r($_GET);
/*
Array
(
[a] => b
[c] => d
)
*/
I want to remove questionmark from querystring with Apache and htaccess, so when a user see my website with this address:
http://project.dev/a=b&c=d
It will be identical to this address:
http://project.dev/?a=b&c=d
and I can access the querystring as before: with $_GET superglobal array.
Some Important Notes:
-
I don’t want to redirect user from URL without question mark to the URL with question mark.
-
I have both
GETandPOSTrequests to this page. -
The querystring can have questionmark
?itself, for example:
http://project.dev/?a=b&c=d?x=y. -
I want the addresses with question mark, automatically redirect to the one without question mark. For example when a user come to my site with this address:
http://project.dev/?a=b&c=d
I want to redirect user to this address:
http://project.dev/a=b&c=d. -
My website has only one page:
index.php. Without any subfolders.
How can I do this in htaccess?
This may be an issue, since the request body doesn’t get included after a redirect. So if you’ve POSTed a request that has GET style params in the query string, the redirect will lose the POST params.
The rules you want will probably look something like this:
If you want a 301 redirect, replace the
Rflag in the first rule withR=301. TheNEflag is needed s othat any encoded?in the query string shows up as%3Finstead of the%getting encoded itself. You can alternatively try replacingRewriteCond %{REQUEST_URI} .=.with-fand-dchecks: