Question about Query String

Typically when I think of a query string, I think of the stuff that comes after the ? following the domain, for example…

Example #1:

But while playing around with $_SERVER[‘QUERY_STRING’], I am now confused!

Let’s say I have another URL like this…

When I run $_SERVER[‘QUERY_STRING’], I see something like this…

Example #2:

1.) So which of these two examples is a Query String?

2.) What do you call the part that comes before the “?”

3.) What do you call the part that comes after the “?”

Is this because you’ve got a redirect working that is actually rewriting your URL in the second example?

On my current project I am using mod_rewrite because my client wants one of those nice looking URLs.

So this would be closer to what I am actually using…

Regardless, I have always called the part after the “?” the “Query String”.

But it looks like PHP’s function uses the terms to mean something different.

In my 3 questions above, I just want to make sure I am referring to things using the proper names!

You are naming them correctly.

Apache passes the “nice URL” to PHP so as far as PHP is concerned the URL being used is not the “nice” one.

You’re looking at it from a humanistic perspective. You need to look at it through the machine perspective. The querystring would include the gender even though it doesn’t follow the ?

I would venture to guess that you see something like RewriteRule ^/?([a-zA-Z_]+)/([a-zA-Z_]+)$ index.php?gender=$1&category=$2 [L]

So it will take the two items here and pre-pend them onto the existing querystring. You’ll just need to account for those two items in your querystring processing…

1 Like



So this whole topic came up because I am writing code to parse up the submitted URL and stick it in a log.

My code is working, but I found myself getting confused because I never really realized how Apache was prepending things onto the Query String.

Is there another name I could use to call the whole prepended Query String, or am I stuck with two similar Query Strings?

Maybe the long one could be called the “Server Query String”, and the traditional one after the ? could be called the “URL Query String”? :confused:

I would probably call it “rewritten query string”

And is it Apache or PHP that is rewriting the “nice URL” to make the longer “rewritten Query String”?

where does this happen??

So the user submits the nice URL with a query string after the ?, and Apache rewrites the nice URL to a standard URL where the “nice” part now becomes part of the “Query String”, right?

And then PHP takes this extended “Query String” and returns the whole thing when I use $_SERVER[‘QUERY_STRING’], right?


This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.