rvincenten
05-15-2010, 01: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 serverhttp://example.com/img/pics/pic1.jpg
Fictional path that supplies width and heighthttp://example.com/img/pics/pic1.w150h100.jpg
Rewritten path to the PHP scripthttp://example.com/index.php?mode=thumbnail&basepath=/img/pics/pic1&extension=jpg&width=150&height=100
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]
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 serverhttp://example.com/img/pics/pic1.jpg
Fictional path that supplies width and heighthttp://example.com/img/pics/pic1.w150h100.jpg
Rewritten path to the PHP scripthttp://example.com/index.php?mode=thumbnail&basepath=/img/pics/pic1&extension=jpg&width=150&height=100
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]