Home > Mobile >  Allow PHP to read GET with RewriteRule
Allow PHP to read GET with RewriteRule

Time:12-14

RewriteRule ^cards/([^/]*)/([^/]*)$ /cards/?name=$1&page=$2 [L]

Hi. I have this inside my .htaccess. If I add ?extra=1 to the end of the url and then var_dump, it doesn't read the $_GET['extra']; Is there a flag that works?

I saw here some extra flags but none seems of any use in this particular situation.

CodePudding user response:

I saw here some extra flags but none seems of any use in this particular situation.

If you are expecting the query string on the original request to be merged with the query string in the RewriteRule substitution (2nd argument of the RewriteRule directive) then you need to add the QSA flag (Query String Append) to your rule. The default behaviour is that any query string in the substitution will override the request.

However, you should be rewriting to the actual file that handles the request, not the directory (and presumably expecting mod_dir to issue an internal subrequest for the directory index).

For example:

RewriteRule ^cards/([^/] )/([^/]*)$ /cards/index.php?name=$1&page=$2 [QSA,L]

Aside: I also changed the first quantifier from * to since the path segment cannot be empty for the rule to be successful.

  • Related