i have a script that uploads images, creates a hash for it, creates 3 directories, and stores the image to


(the “536_” is the user id)

so im trying to turn




how can i do that? i want that if someone wants to view the photo, they see the new directory in the url, not the one with 3 sub directories.


So jon's method works but but i need to add RewriteRule .* index.php/$1 [PT,L] to my htaccess. when i add that, everything stops working how come?

this is what i currently have so far

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$1 [PT,L]
RewriteRule ^user_pics/([^/]+)/[^]+(.{3})(.{3})(.{3})(.*).(jpe?g|gif|png)$ /imgs/$2/$3/$4/$1_$2$3$4$5.$6 [L]

  • for "108_" you mean, in the url u gave "536_" ? why do you create all those folders to save the imagen?
    – jpganz18
    Sep 17, 2012 at 21:26
  • sorry fixed :p. and i created them because there will be A LOT (millions) of pictures on this server so they need to be spread evenly
    – flyenig
    Sep 17, 2012 at 21:31
  • added edits to this question....
    – flyenig
    Sep 17, 2012 at 22:37

1 Answer 1



RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^user_pics/([^/]+)/[^_]+_(.{3})(.{3})(.{3})(.*)\.(jpe?g|gif|png)$ /imgs/$2/$3/$4/$1_$2$3$4$5.$6 [L]
  • thanks but that didnt work
    – flyenig
    Sep 17, 2012 at 22:28
  • nvm it worked but there is a problem... i need to have this rule in my htaccess RewriteRule .* index.php/$1 [PT,L] when i take it out it works, but when i put it in it doesnt. why>?
    – flyenig
    Sep 17, 2012 at 22:33
  • @flyenig You want to put the redirect rule above any routing rules (e.g. your "route everything to index.php" rule).
    – Jon Lin
    Sep 17, 2012 at 22:38
  • ok i put that before the index.php rule and now my whole site gives me a 500 error, what am i doing wrong?
    – flyenig
    Sep 17, 2012 at 23:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.