Go Back   CodingForums.com > :: Server side development > Apache configuration

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-15-2010, 01:56 PM   PM User | #1
rvincenten
New Coder

 
Join Date: May 2010
Posts: 69
Thanks: 3
Thanked 10 Times in 10 Posts
rvincenten is an unknown quantity at this point
Need help with rewriting rules (thumbnails)

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
Code:
http://example.com/img/pics/pic1.jpg
Fictional path that supplies width and height
Code:
http://example.com/img/pics/pic1.w150h100.jpg
Rewritten path to the PHP script
Code:
http://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:
Code:
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:
Code:
# 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]
rvincenten is offline   Reply With Quote
Old 05-16-2010, 07:06 AM   PM User | #2
oracleguy
Rockstar Coder


 
Join Date: Jun 2002
Location: USA
Posts: 9,043
Thanks: 1
Thanked 322 Times in 318 Posts
oracleguy is a jewel in the roughoracleguy is a jewel in the roughoracleguy is a jewel in the rough
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?
__________________
OracleGuy
oracleguy is offline   Reply With Quote
Old 05-16-2010, 11:49 AM   PM User | #3
rvincenten
New Coder

 
Join Date: May 2010
Posts: 69
Thanks: 3
Thanked 10 Times in 10 Posts
rvincenten is an unknown quantity at this point
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

Last edited by rvincenten; 05-16-2010 at 01:01 PM..
rvincenten is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:10 PM.


Advertisement
Log in to turn off these ads.