0

So, I'm having a difficult time understanding QSA. Since

RewriteRule ^search/(.*)$ search.php?s=$1 [NC,L,B,QSA]
RewriteRule ^search/(.*)$ search.php?s=$1 [NC,L,B]

Both give me the same result. I read that QSA appends any parameters passed (at least I think that's what I understood from it). However it's not exactly working for me.

Currently I have the url

http://localhost:8888/search/hey+i%27m+a+search+query&SortBy=day

which returns

hey i'm a search query&SortBy=day

I can set it to

RewriteRule ^search/(.*)&SortBy=(.*)$ search.php?s=$1&SortBy=$2 [NC,L,B,QSA]

which will successfully return the get parameter, but I from what I understand about the QSA, it should be automatically handled...right?

I got my information from here - What does $1 [QSA,L] mean in my .htaccess file?

Basically, my question is, why should I use QSA? And what kind of benefits would it provide in this situation? (Sorry for being blunt, but I can't get a good grasp of this)

Community
  • 1
  • 1
Trevor Wood
  • 2,347
  • 5
  • 31
  • 56

1 Answers1

2

The problem is that your example URL has no query string. You use ? to designate the query string:

http://localhost:8888/search/hey+i%27m+a+search+query?SortBy=day

The ?SortBy=day will be automatically appended to the rewritten query string through the QSA flag.

Anonymous
  • 11,748
  • 6
  • 35
  • 57
  • Ah, thanks man. I was thinking SortBy would be the second GET parameter but since the search query is written into the rewrite rule SortBy is considered the first rule, right? – Trevor Wood Jan 16 '16 at 03:46
  • 1
    No problem. SortBy is not the first query parameter after the rewrite. The reason you need to use `?` is because otherwise .htaccess sees no query string. It does all the merging on it's own, but if it doesn't see it in the first place, it has nothing to merge to. – Anonymous Jan 16 '16 at 03:49
  • Ah okay, so placement doesn't really matter here it's just declaring that there are GET parameters that need handling. Thank you! – Trevor Wood Jan 17 '16 at 02:42