0

I'm calling a cfm file form htaccess to perform some manipulation on images like so:

<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    ...
    RewriteRule   \.(jpg|jpeg|gif|png) services/adaptive-images.cfm
</IfModule>

Inside the cfm file I'm resizing the image.

Question:
Would this also be possible by calling a method inside a cfc file? Something like this:

    RewriteRule   \.(jpg|jpeg|gif|png) services/ai.cfc?method=resize

Is there a way to make this work?

Thanks for any info!

frequent
  • 27,643
  • 59
  • 181
  • 333
  • 1
    Well... Have you tried? If yes, any problems/errors? – Sergey Galashyn Jun 10 '12 at 05:31
  • yes, i tried. Using the above snippet results in server error – frequent Jun 10 '12 at 05:45
  • trying to nail it down to something more explainable (from 500 internal server error) – frequent Jun 10 '12 at 07:51
  • On a side note, do you REALLY want to be resizing your images each time they're requested like that? Would it not be better to resize them once, and then just request the resized version? There might be more to this than is obvious from your code snippets, so it might well be a legit exercise. However I'd not be wanting to resize images any more than once, and then serve them up statically thereafter, if poss. – Adam Cameron Jun 10 '12 at 11:45
  • @AdamCameron - no, I don't. I'm trying to get this to work: https://github.com/cfjedimaster/Adaptive-Images, which also saves images to the cache once they are requested the first time. I have it working using a cfm file from htaccess, but I'd rather have it a cfc, therefore my question was whether this was possible. – frequent Jun 10 '12 at 12:15

1 Answers1

3

The question you're asking can be distilled down to a couple of components:

  1. Can a CFC method be called via HTTP?
  2. Can a rewrite rule make an HTTP request?

Obviously the answer to the second one is "yes". And - as you seem to already know - the answer to the first one is also "yes". You demonstrate the syntax for this in your RewriteRule.

The thing you need to consider here is that CF just receives requests from the web server to fulfil an HTTP request. CF doesn't know (or care) whether the request can straight through from the web server unadulterated, or whether it was rewritten by the rewrite module first.

So... if you're getting an error, it's something else. What you're trying to do from a web server / rewrite module / CF standpoint is entirely possible.

I suggest you have a look at your logs and see what's causing the 500 error. Indeed if you have robust exception handling enabled, you should be getting the cause of the error displayed on the screen.

What happens if you call the URL you're rewriting to directly via the browser address bar?

Adam Cameron
  • 29,677
  • 4
  • 37
  • 78