4

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:

http://localhost/img/z1uABC.jpg

The applied rule redirect to:

http://localhost/image-servlet/img/ABC

The final URL miss the query-string substitution:

?z=$1&url=$2

And are replaced just by:

$2

Anybody can help me with my mistake?

Thank,

And Past

Andre Pastore
  • 163
  • 1
  • 12
  • I assume you have the PT switch on for a reason...what other directives are modifying the URL? – Kev Oct 08 '09 at 20:47
  • "/image-servlet" is an "Alias" mapped to mod_jk handler. If I remove PT directive, the request don't responds. – Andre Pastore Oct 08 '09 at 21:28
  • 1
    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 00:34

5 Answers5

2

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

Jorge Bernal
  • 454
  • 1
  • 3
  • 9
1

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.

1

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

Host: foohost.com

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

0

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

malonso
  • 365
  • 2
  • 9
0

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

Philip Wigg
  • 104
  • 4