View Full Version : Need help with rewriting rules (thumbnails)

05-15-2010, 02:56 PM
Hey there,

For a project I'm doing for school I need to use mod_rewrite and php together. My idea was making a thumbnail generator in PHP, and using mod_rewrite to link to the script. The script will then generate the thumbnail of the supplied url and store it in a cache directory.

I was thinking about using this as an example:

Real path of the image on the server

Fictional path that supplies width and height

Rewritten path to the PHP script

Now quite obviously, I tried experimenting with some rewriting, except I get 500's all the time.

My RewriteRule directive looks like this:
RewriteRule ^(.+)\.w([0-9]+)h([0-9]+)\.(jpg|jpeg|png|gif)$ ?mode=thumbnail&basepath=$1&extension=$4&width=$2&height=$3 [L]

My entire .htaccess file looks like this:
# AddHandler x-httpd-php5 .php

ErrorDocument 404 /404.html
Options +FollowSymLinks -MultiViews +Indexes

RewriteEngine on
RewriteBase /

#send to script which applies a mask to the image
RewriteRule ^img/headers/([^/]*)\.png$ /?header=$1 [L]

#rewrite thumbnails
RewriteRule ^(.+)\.w([0-9]+)h([0-9]+)\.(jpg|jpeg|png|gif)$ /?mode=thumbnail&basepath=$1&extension=$4&width=$2&height=$3 [L]

#rewrite for trying to visit top level index.php
RewriteRule ^/index\.php$ / [L,R=301]

# go away hackers
RewriteCond %{REQUEST_FILENAME} -d [or]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule \.php$ / [R=301,L]

# root
RewriteRule ^/$ /?__subsite=none [L,QSA]
# pages from root site
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]*)\.html$ /?__doc=$1 [L,QSA]
# fix slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/$ /?__subsite=$1 [L,QSA]

RewriteRule ^([^/]*)/([^/]*)\.html$ /?__subsite=$1&__doc=$2 [L,QSA]

05-16-2010, 08:06 AM
If you look in the error log for the site it will tell you what the problem is in more specific terms.

Are your images always going to be under the /img folder some place?

05-16-2010, 12:49 PM
Not always, Photo's are going to be in subdirectories of the directory fotos and header images are going to be under img/headers. I haven't decided where to put uploaded images yet, have to decide about the WYSIWYG editor yet :).

Funny enough, the problem solved itself :)