Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just want to set a location for a single page:


(and other pages 1,2 as well)

I'm writing in the config:

location ~* ^.+showthread\.php\?t=2589.+$ {

This online tester says that the string matches: But actually it does not. WTF? Does nginx use "special" regexp or what? How to make the right expression?

share|improve this question
up vote 1 down vote accepted

Use a tilde:

location ~ ^.+showthread.php\?t=2589.+$

to indicate a regex, otherwise nginx treats it as literal.


I'm sorry, I was reading too quickly, and focused on your typo instead of the query string.

So, the trick is that "location" matches on the location, which is /showthread.php. The rest of your query string are GET parameters and won't be in the thing that you're trying to pattern match.

Take a look at the documentation:

So, you'd need something like:

location /showthread.php {
  if ($arg_t = '2589') {
     # do some stuff
share|improve this answer
Just tried, but it doesn't work. What do you mean with "otherwise nginx treats it as literal." ? Official docs say that “~*” is for case-insensitive regex, “~” for sensitive – ABTOMAT Mar 16 '12 at 19:22
Awww! Just saw it: I mistaked in my question. There WAS "~*" (just edited) but still doesn't work. – ABTOMAT Mar 16 '12 at 19:24
@ABTOMAT, Please check my update – cjc Mar 16 '12 at 19:33
Thanks for update. I tried if directive, but now it says "proxy_ignore_headers" directive is not allowed here in (if condition), i use "proxy_ignore_headers" inside the if body (# do some stuff). That's strange that I can do something beyound "if" but can't inside... Anyway even this doesn't help – ABTOMAT Mar 16 '12 at 19:46
Oh, yes. There's a bunch of stuff that doesn't work in an "if" block. Can you post the actual thing you're trying to do? – cjc Mar 16 '12 at 19:53

Nginx locations only match the URI stem, and not the parameters passed in (the stuff after the question mark).

So your location is going to need to be something simple like

  location /showthread.php {/*some stuff*/}

If you want different nginx behavior depending on the value of parameters, you will likely have to use an if block inside that location with a regex on the parameters to rewrite/redirect or do whatever else you need.

If you control showthread.php, it's probably best to add this complexity there rather than in your nginx configuration.

See this link for more information.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.