My guess is that your RewriteRule is way too general, so rather than rewriting just that particular URL, you’re actually rewriting every .jpg you use anywhere on your site!
As a result, in your particular problem at hand, you’re rewriting and redirecting yourself in a circle, like so:
- You navigate to http://mysite.com/image/mycode.jpg
- The rewrite rule matches and calls for the script at /image/mycode.php
- That script returns a redirect to http://mysite.com/image/15.jpg
- The browser requests that URL
- The rewrite rule matches and calls for the file at /image/15.php
- Apache can’t find a file there and returns a 404 File Not Found message to the browser
To get around this, make your RewriteRule more specific:
RewriteRule ^(.*mycode)\.jpg $1.php Now, it’ll only try to rewrite URLs with mycode.jpg, so 5 and 6 above will never happen, and you should get the result you’re after.