42

I'm having issues keeping the parameters of the URL working after an .htaccess URL rewrite.

My .htaccess rewrite is as follows:

 RewriteEngine on
 RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?lang=$1&page=$2

Which means:

example.com/index.php?lang=en&page=product displays as example.com/en/product

For some reason, when I add a ?model=AB123&color=something at the end of my URLs I am not able to retrieve those parameters in PHP using $_GET['model'] and $_GET['color'] even though they are present in the displayed URL.

Why aren't the variables passed along?

Stephen Ostermiller
  • 23,933
  • 14
  • 88
  • 109
Enkay
  • 1,898
  • 6
  • 24
  • 35

1 Answers1

90

You need to append with the [QSA] (query string append) tag. Try

RewriteEngine on
RewriteRule ^([a-z]{2,2})/([a-zA-Z0-9_-]+)$ index.php?lang=$1&page=$2 [QSA]

See http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html

Simon
  • 5,158
  • 8
  • 43
  • 65
  • 4
    Thank you very much. That worked. It's funny how simple the solution is after some of the things I tried... – Enkay Nov 01 '10 at 17:09
  • 2
    It doesn't seem to work on mine, even with the QSA tag. The correct page displays, but because the $_GET seems unobtainable, it throws loads of errors. I'm using `RewriteRule ^details/([^/])/?$ details?Pin=$1 [QSA]` – Lee Dec 04 '14 at 09:37
  • You sir are a legend :) – Fadi Obaji Dec 28 '17 at 20:16