Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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 am trying to make use of an image processing app. It requires an Apache directive in a .htaccess file. But no matter what I do to the RewriteRule, I cannot getting it to work. Causes a Server 500 error.

The rule is:

RewriteRule \.(?:jpe?g|gif|png)$ adaptive-images.php

This should take any jpg/gif/png file and send it over to the adaptive-images.php file, where it will be run through a process for image sizing.

At this point I am beyond my expertise for RewriteRules.

share|improve this question

The first parameter of the RewriteRule directive is a regex so you need to escape the period: \.. Your rule also won't match because you need to match against the whole URI and not just the file extension. Thus the .* is necessary to match whatever might come before the extension (e.g. filename.jpg or /images/filename.jpg).

RewriteRule .*\.(?:jpe?g|gif|png)$ adaptive-images.php

I don't believe forgetting this will cause a 500 error on its own so you should review your Apache error log for more details if this doesn't fix the issue.

Also, using this redirect won't "send" the image file anywhere unless you are doing some trickery in PHP to read the HTTP referer as otherwise the redirected page will have no knowledge of which image it was "passed."

share|improve this answer
PHP will see the original request in $_SERVER["REQUEST_URI"]. – Michael Hampton Oct 11 '12 at 2:58
Either way my point was it has to be stripped from a superglobal which are highly server-dependent and not always present. It would be more effective to redirect with the image in the URI as a GET variable IMO. – Garrett Oct 11 '12 at 3:03
Now you're getting into issues of programming, which we don't really do here. :) – Michael Hampton Oct 11 '12 at 3:09
I merely meant it as a helpful aside since the OP clearly stated they're not much of a mod_rewrite guru. But alas, here we are. :) – Garrett Oct 11 '12 at 3:14
Thanks gman. I actually tried it with the beginning slash and still failed. I did go look at the error logs and I did not see any reference to the issue in the log, so I am at a loss. – erick_the_redd Oct 11 '12 at 4:57

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.