views:

32

answers:

1

I'm trying to do something like the following in my .htaccess file:

Alias /assets /location/of/files

RewriteCond %{REQUEST_URI} ^/assets/[0-9]+.jpg$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* /build_thumbnail.cfm?path=%{REQUEST_URI} [QSA,L]

So in theory it's quite straightforward:

  • an image is requested from a url starting with /assets/
  • apache checks for the existence of the file
  • if found, the file is served
  • if not, a script is run instead

This is working fine in other places but this is the first time I've tried to use it on a directory included as an Alias. As I understand it Mod Rewrite runs before Mod Alias which would surely cause this not to work (and in truth my Alias line is in the apache conf while the rest is in .htaccess).

Is there a way to get Mod Rewrite to acknowledge the Aliased directory?

Is it possible to change the Alias line to a Rewrite line instead?

A: 

Try -F instead to invoke a subrequest:

RewriteCond %{REQUEST_URI} ^/assets/[0-9]+.jpg$
RewriteCond %{REQUEST_FILENAME} !-F
RewriteRule .* /build_thumbnail.cfm?path=%{REQUEST_URI} [QSA,L]
Gumbo
Interesting idea, I wasn't aware that you could do that. Still not working for me unfortunately. # this just 404s (seems like the Alias mapping for assets # in the apache conf means that it doesn't even get here) RewriteCond %{REQUEST_URI} ^/assets/[0-9]+.jpg$ RewriteRule .* /build_thumbnail.cfm [QSA,L] # this works because img is a real directory in the web root RewriteCond %{REQUEST_URI} ^/img/[0-9]+.jpg$ RewriteRule .* /build_thumbnail.cfm [QSA,L]
Aidan Kane