I am trying to rewrite a URL with 1 fixed parameter.
localhost/login
localhost/signup
to
localhost/account.php?action=log
localhost/account.php?action=reg
it worked fine with this
RewriteRule ^login$ account.php?action=log [NC,L]
RewriteRule ^signup$ account.php?action=reg [NC,L]
but when I added Google oauth it returns a URL like this
localhost/login?code=.....
so I changed it to
RewriteRule ^login?(.*)$ account.php?action=log&code=$1 [NC,L]
but I couldn't get the code variable with $_GET['code']
and var_dump($_GET)
returns
array(2) { ["action"]=> string(3) "log" ["code"]=> string(0) "" }
CodePudding user response:
RewriteRule matches against the path component of the URL only, you can not check the query string with that, that would need a RewriteCond.
But you should not need anything in addition to the already existing ^login$
redirect - just add the QSA
flag, so that the original query string gets merged with your existing one.
RewriteRule ^login$ account.php?action=log [QSA,NC,L]