'Can I still use get parameters if I rewrote the url with the .htaccess RewriteRule?

I'm a bit confused and I need help to finish a project, so thank you for your answers. I will not post my code because its very messy but I'll use an example:

Let's assume I have a url like this:

http://localhost/mySite?q=bar&g=foo

And let's assume I have a rewrite rule like this:

RewriteRule ^mySite/bookingConfirmed$ mySite.php?q=$1&g=$2

First question: If I have link with href=mySite?q=bar&g=foo and click on it, the url showed in the reached page will be like the rewrote one or it will still be like it was written in the href?

Second question: If I have a php code like this:

$q = $_GET['q']; 

Does $q will read the q parameter if I have a rewrote url?

Thank you all again.

EDIT:

I'm asking this because I have a very dirty url coming from the server from which I take some data of a just recorded booking (like the day, the client name ecc). I need this data to start a little script, which read them from a input type hidden.



Solution 1:[1]

Rewrite rules, in their default mode, take the URL sent by the browser, and pretend that a different URL was requested instead.

For instance, if you have the rule:

RewriteRule (.*)/(.*) example.php?a=$1&b=$2

If you type https://example.com/foo/bar into the browser, the rule will transform that to /example.php?a=foo&b=bar. As far as the browser is concerned, nothing has happened; as far as PHP is concerned, https://example.com/example.php?a=foo&b=bar is the URL that was requested, and everything like $_GET works exactly as normal.

Note that it is generally a mistake to think of rewrite rules as "making URLs pretty". The input is the pretty URL, and the rewrite rule tells the server how to interpret that URL. You can't use a rewrite rule to "hide" parameters, because if the browser doesn't send them, you can't see them.

There are a couple of relevant details:

  • If you add the [R] flag to a rule, it does tell the browser to request the new URL, instead of pretending that's what was requested right now. This also happens automatically if you give an absolute URL as the target (starting http:// or https://) rather than a relative one.
  • If you have a URL like https://example.com/foo/bar?name=bob, you can add the [QSA] flag to a rule to copy the name=bob parameter onto the rewritten URL, giving in this example /example.php?a=foo&b=bar&name=bob

For more details and further links, see Reference: mod_rewrite, URL rewriting and "pretty links" explained

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MrWhite