[SOLVED] Lighttpd rewrite rule (php document generating image files)
Added by meinemitternacht about 15 years ago
I have a web application I'm developing, and one of the pages generates PNG images using php's GD library. Well, I'm also using thickbox to display these images. The problem is that since the php file has the php extension, it displays the PNG as text. I would like to tell my page to reference example.png instead of example.php and let lighttpd rewrite using this kind of rule:
(docroot)/graph/var1/var2/var3/example.png => example.php?var1=blah&var2=blah&var3=blah
Can anyone provide me with a starting point?
Replies (8)
RE: Lighttpd rewrite rule (php document generating image files) - Added by patrickdk about 15 years ago
Try fixing your php script.
Add a content-type header.
Your issue has nothing to do with needing a rewrite (though a rewrite would make the url look nicer)
RE: Lighttpd rewrite rule (php document generating image files) - Added by meinemitternacht about 15 years ago
The script does put a image type of PNG in the header. My issue is with thickbox not recognizing this. The browser displays the images perfectly.
Edit: I'm very sure of what I need, I just don't know how to write the expression.
RE: Lighttpd rewrite rule (php document generating image files) - Added by meinemitternacht about 15 years ago
If you would like to look up the php library I am using, it's phpgraphlib. I'm calling data from the MySQL database and throwing it in a graph. This whole setup worked with lightbox, but I needed to move to Thickbox for other reasons, and it works differently. It doesn't wrap the content in a <div> it actually fetches the content using JQuery, which is where the problem starts. It doesn't know to display the .php file as a .png file. See where I'm going with this?
RE: Lighttpd rewrite rule (php document generating image files) - Added by patrickdk about 15 years ago
Submit a thickbox bug then, that it ignores the content-type header :)
http://redmine.lighttpd.net/wiki/1/Docs:ModRewrite
something like:
url.rewrite-once = ("^/graph/([^/]+)/([^/]+)/([^/]+)/" => "/example.php?var1=$1&var2=$2&var3=$3" );
RE: Lighttpd rewrite rule (php document generating image files) - Added by meinemitternacht about 15 years ago
Thank you very much :) I really don't think there's much active development on Thickbox, or that they would want to change how they do things over this one issue. It's much easier to rewrite the URL :)
RE: Lighttpd rewrite rule (php document generating image files) - Added by meinemitternacht about 15 years ago
I'm getting a "404 not found" when trying to use that rewrite rule. If I'm just using the default lighttpd host (localhost, /var/www) then I can put that rule at the end of lighttpd.conf and enable mod_rewrite and have it work, correct? It seems as if it should work, I even tried this modification:
url.rewrite-once = ("/perfmon/graph/([^/]+)/([^/]+)/([^/]+)/" => "/perfmon/graph.php?table=$1&testid=$2&type=$3")
RE: Lighttpd rewrite rule (php document generating image files) - Added by meinemitternacht about 15 years ago
Hold on, it's not giving me a 404 error anymore. I changed it to url.rewrite = ( and it's sort-of working. However, I don't think the PHP script likes what I'm doing. I'll do some error catching and see what's going on.
RE: Lighttpd rewrite rule (php document generating image files) - Added by meinemitternacht about 15 years ago
It's working! Thanks :)