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 registered a RewriteRule with mod_rewrite, but the substituted URL are wrong.

The rule are:

RewriteRule ^/img/z(0|1)u(.+)\.(gif|jpg|jpeg|png)$ /image-servlet/img/?z=$1&url=$2 [NE,QSA,PT,T=image/$3]

When I access the following URL:


The applied rule redirect to:


The final URL miss the query-string substitution:


And are replaced just by:


Anybody can help me with my mistake?


And Past

share|improve this question
I assume you have the PT switch on for a reason...what other directives are modifying the URL? – Kev Oct 8 '09 at 20:47
"/image-servlet" is an "Alias" mapped to mod_jk handler. If I remove PT directive, the request don't responds. – apast Oct 8 '09 at 21:28
Hmm...I don't have any experience with mod_jk. From what I can tell, what you've posted is correct, and I verified the regex works, so my guess is that the problem lies somewhere else than in what you have here (it is just a guess though.) – Kev Oct 17 '09 at 0:34
up vote 1 down vote accepted

I know it's ugly, and even more inefficient, but have you tried:

RewriteRule ^/img/z(.+)u(.+)\.(.+)$ /image-servlet/img/?z=$1&url=$2 [NE,QSA,PT,T=image/$3]

I seem to remember that mod_rewrite will only match (.+) or (.*) to a variable. Obviously (from your example), it's the only thing that's being correctly rewritten.

Of course, that mod_rewrite rule will take forever to match, and requires that the script do some input validation.

Also, apache supports the TRACE http command, which is good for tracking down multiple (accidental) rewrites. Just swap the GET in the http request with TRACE, for example:

TRACE /z1uABC.jpg HTTP/1.1


Lastly, if you're still stuck, try running the LiveHeader or Firebug firefox extensions.

share|improve this answer

You can also set RewriteLog and RewriteLogLevel and see if it helps

share|improve this answer

Try removing QSA from your flags; in your example you are not presented with an initial query string -- QSA and a ? in the substitution will combine them, which isn't what your pattern dictates; it may be what's screwing things up. The use of NE is not warranted either given your pattern input, but it shouldn't be causing a problem. You really only need [PT,T=image/$3] I think.

share|improve this answer

Can you show us the contents of the $_GET variable via print_or or something like that?

share|improve this answer

Can you also show us the mod_jk config from your httpd.conf? I don't understand why you need an Alias directive.

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.