Jump to content

Recommended Posts

I've got a system where every image on my server has a watermarked version cached. If the file is test.gif, the watermark is test_wm.gif

 

At the moment every request for an image gets sent to a php file which serves up the cached version or makes a new one if there isn't a cached version using this line in htaccess. This works fine.

 

RewriteRule ^(.+).gif$ wm.php?src=$1.gif

 

Last night I was playing around trying to get it to redirect based on whether the file exists or not, and then mysteriously everything stopped working. So I started stripping it back and trying to find what the problem was. Now, even this rule does not work.

 

RewriteRule ^(.+).gif$ $1_wm.gif

 

It serves up a broken image instead of the watermarked one. Yet, this rule works as intended.

 

RewriteRule ^(.+).gif$ $1.gif

 

Is there something obviously wrong with my rule that I'm just not seeing because I've been staring at it too long? Or should I be talking to my host about a messed up apache?

Link to comment
https://forums.phpfreaks.com/topic/88823-rewrite-mysteriously-not-working/
Share on other sites

Very difficult to say - what might be likely is that you have another ruleset which is acting on this one unintentionally

 

The best way to debug is to enable rewrite logging - use tail -f (Windows or Linux) and watch the log-end sequence

If the rewrite appears to rewrite the URI correctly with no interference from other rules you can then also watch the access/error logs using tail to see what actual file "hits" the server is seeing. If there are cache or improper filename problems then you may see this in the error log.

 

You may need RewriteLogLevel 5 or higher and it may help if you're really stuck to set Apache log level to debug briefly

 

Don't forget to disable rewrite logging after and reset any debug log levels back down to normal.

 

I assume you're using Apache 2.3 (or 2.2??) with Apache cacheing. Never used it myself I use Apache 2.0 and wrote my own cache module when I needed it using mod_rewrite so not sure what problems the cache age etc. might add to this. Might be worth disabling cacheing until the rewrite is solid.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.