How to rewrite the apache URL with variable and then use other variables in PHP?

0

Hello, I do not know if the title of the question makes much sense, but the question is:

I have this code:

RewriteRule ^teste/([a-z]+)$ settings/php/teste.php?lib=$1

It creates a redirect, but when I try to add variables by URL it does not work:

www.meusite.com/teste/ {variable}? id = {variable}

Specifically, everything after the question mark PHP does not recognize as a variable and so I can not execute my scrip. Is there a better way to configure apache so I can rewrite the URL already by adding a default variable as if it were a directory, and then use the variables in a normal way? Or what do you guys suggest so I can use a URL like that?

    
asked by anonymous 25.07.2017 / 03:16

1 answer

1

It seems that the QSA flag is missing from your route.

RewriteRule ^teste/([a-z]+)$ settings/php/teste.php?lib=$1 [QSA]

See DOC :

  

When the URI contains a query string, the default behavior   of RewriteRule is to discard the existing query string, and replace it   with the newly generated one. Using the [QSA] flag causes the query   strings to be combined.

     

Consider the following rule:

     

RewriteRule "/pages/(.+)" "/page.php?page=$1" [QSA]

     

With the [QSA] flag, a request for / pages / 123? one = two will be mapped   to /page.php?page=123&one=two. Without the [QSA] flag, that same   request will be mapped to /page.php?page=123 - that is, the existing   query string will be discarded

    
25.07.2017 / 09:49