0

I have the following rules in my htaccess

RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .+ redirect.php [L]
RewriteRule ^(.*)\.(?!js|css|png)([^.]*)$ redirect.php [L]

everything works perfect except for one thing, the querystring.
for some reason the querystring disapper...

I got the following url myweb.com/subscribe?email=blablabla in redirect.php I have the following line:

echo $_GET['email']; //should echo the email

and it doesnt echo anything...
*I checked that it does rewrite to redirect.php

any Idea why and how to fix it?

Ron
  • 3,975
  • 17
  • 80
  • 130
  • 2
    possible duplicate of [.htaccess RewriteRule to preserve GET URL parameters](http://stackoverflow.com/questions/4071155/htaccess-rewriterule-to-preserve-get-url-parameters) – mario Mar 10 '13 at 14:56
  • QSA flag didnt work. I tried everything... – Ron Mar 10 '13 at 15:03
  • Note you have 2 rules, use `QSA`, which _is_ the correct answer, in both. – Wrikken Mar 10 '13 at 15:44
  • @Wrikken ofc, I did it in both and it didnt work.. I am not that idiot just a little bit – Ron Mar 10 '13 at 16:08
  • 1
    Let's be clear, `QSA` (or Leonard's answer for that matter) works, so something else must be going on. More redirects somewhere maybe? You could make the redirects temporarily external (`[R]`) to check in the network log of your browser what & how things are happening. – Wrikken Mar 10 '13 at 16:27
  • Using [R] cause the web to redirect to redirect.php?email=blablabla as it should and it echo the email. Why without the R flag it doesnt work? – Ron Mar 10 '13 at 16:34
  • Ok I investigated it a little more and the problem seem to be with RewriteRule ^(.*)\.(?!js|css|png)([^.]*)$ redirect.php [QSA,L] – Ron Mar 10 '13 at 16:40

1 Answers1

0

Solved it by the following steps:

  1. I didnt want to rewrite css, js, png etc.. files so in my last rule it was included in the regex - I splitted it.
  2. Added [QSA] flag to 2 last rules
  3. Added RewriteCond %{REQUEST_FILENAME} !-f
  4. Changed RewriteCond %{REQUEST_FILENAME} -d to RewriteCond %{REQUEST_FILENAME} !-d.

this is how it looks:

RewriteEngine on
RewriteBase /
RewriteRule \.(ico|css|png|js|txt|xml)$ - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .+ redirect.php [QSA,L]
RewriteRule ^(.*)$ redirect.php [QSA,L]
Ron
  • 3,975
  • 17
  • 80
  • 130