PDA

View Full Version : mod_rewrite for images



Portucuenta
05-08-2010, 12:20 PM
hello everybody, I am not quite sure if this is the correct thread to write in

I want to know if it is possible, and if so, how is it done, that when I write the url of an uploaded image in one of my posts
for example:
/wp-content/uploads/2010/05/pic.jpg

calls a
/phpFile.php?path=pic.jpg

I want this only for jpg, gif and png uploaded files

I don't know if it is possible, as the url of the file actually exists, and will load that image, but I want to do something over that image before showing it (watermark)

I tried with

RewriteEngine On
RewriteRule ^wp-content/uploads/([^-]*)$ /wphpFile.php?path=$1 [L]

but without any success

can you help me out?

thanks in advance!

speed
05-08-2010, 03:22 PM
The following should do it:

RewriteRule ^wp-content/uploads/((.*)\.(jpg|gif|png))$ sites.php?path=$1

I've given you the path from the uploads folder as $1 as I'm not sure which part of the path you need.

Portucuenta
05-08-2010, 05:03 PM
thanks for the reply Speed

sadly it isn't working :\

I believe it is because this files already exist, am I right?

I've tried adding
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
but still not making the trick

Portucuenta
05-08-2010, 05:19 PM
0k!

my bad
thanks! :)

it should have been

RewriteCond %{REQUEST_FILENAME} -f

masyk
05-09-2010, 03:41 PM
You should better not be using this... Server is going to die very fast when using this system. That a huge load to use apache and php on every image request...