Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    May 2010
    Posts
    69
    Thanks
    3
    Thanked 10 Times in 10 Posts

    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]

  • #2
    Rockstar Coder
    Join Date
    Jun 2002
    Location
    USA
    Posts
    9,074
    Thanks
    1
    Thanked 328 Times in 324 Posts
    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

  • #3
    New Coder
    Join Date
    May 2010
    Posts
    69
    Thanks
    3
    Thanked 10 Times in 10 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •