Complex rewrite help

Hello all. I’m having a difficult time figuring out how to resolve this issue and thought maybe someone here could help…

I’m using a php-cgi script that is a PHP front-end to ImageMagick so that I can manipulate images on the fly. I have to use php-cgi because the script uses an exec() function. Problem is, the script requires extra path information to be passed to it from the URL string, and that is something php-cgi doesn’t like. It works fine with normal PHP.

The script normally works with a URL like this:



where $id is a variable that points to a unique image ID number. and the “resize…” information gets passed to the script for processing by ImageMagick. But as soon as the URL is changed to:


the script chokes because the URL string can’t be parsed correctly by the php-cgi.

Can this issue be solved with mod_rewrite? I’m not sure how, so if you can give me any pointers, I’d really appreciate it.


It has been awhile since you asked the Dreamhost support forum about your php image manipulation script. I’m trying to do similar manipulation with path info being passed from the URL string. Did you ever get it to work? If so, can you pass along some hints ?
With CGI, and error document 404, Im trying to take URL request:
and redirect the request to:

I experimented with something similar once…

It sounds like you’re currently trying to use an ErrorDocument to handle the requests. That should work without any problem. Your custom 404 page can be a PHP script, so no redirection is necessary. You’d simply create an .htaccess file in your web directory, and add a line like this:

ErrorDocument 404 /not_found.php

Then, in that PHP script, use $_SERVER[‘REQUEST_URI’] to figure out what URL was originally requested.

Another alternative… If you’re just trying to handle URLs that end in numbers in a special way, this might do what you want (again, in an .htaccess file):

RewriteEngine On
RewriteRule ^([0-9]+)$ not_found.php?number=$1

I’m not an expert on these things, but hopefully this is the right idea…

Herecast: Location-aware services with Wi-Fi