简体   繁体   中英

Impossible to mod_rewrite based on existence of file in mod_aliased directory?

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?

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM