0

I have a Wordpress website, due to some limits i need to have originals of the photo at the serverside, but watermarked ones on a frontend and with direct opening of the photos. I'm using Frontend content creation plugin and (as i understand) not all the plugins will fork with custom file input fields (wp_handle_upload used). I've found good solution: php file + htaccess setting with RewriteRule. The problem is that it isn't work for me for some reason.

The solution is: http://dolcepixel.com/how-to-watermark-all-your-uploaded-images/

When i opening file with:

/watermark.php?p=br&q=90&src=wp-content/uploads/link/to/file.jpg

everything is good, watermark is on the image, but when this image loads on the page or direct link in the browser - nothing happens. It loads original image without watermaks.

There is two main settings: htaccess rule

RewriteRule ^wp-content/uploads/(.*\.(jpe?g|gif|png))$ watermark.php?p=br&q=90&src=wp-content/uploads/$1

And full block of mod_rewrite section:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^wp-content/uploads/(.*\.(jpe?g|gif|png))$ watermark.php?p=br&q=90&src=wp-content/uploads/$1
</IfModule>

the php file is bigger and it's works as i see, the problem is in something else, but you can find the .php at the link on top of the post.

Whats the problem with me, or Apache, .htaccess or with Wordpress? If there is a way to deny any access to /uploads/ with possibility to open images throught php proxy – it is a solution also, but when i'm trying to use /wp-content/uploads/.htaccess with "deny from all" it wont work and the direct file is opens without any problems with browser.

UPDATE: The rule is not working even after the RewriteBase rule

2 Answers 2

0

The rewrite condition !-f means "if file does not exist". Since the files exist, the rule is never reached. Just changing the order should fix the problem.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^wp-content/uploads/(.*\.(jpe?g|gif|png))$ watermark.php?p=br&q=90&src=wp-content/uploads/$1 [L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
0

I am not much of expert on .htacess, but as far as I remember basic WP rules are designed to skip existing files and directories (and have web server just serve them rather than pass on to WP core).

From looking at your snippet I would guess your custom logic is probably simply never reached, because the check for file/directory fires before it and stops going further.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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