apache/mod_rewrite returns an existing files from a defined folder if it exists else a default one
I'd like to write a .htaccess for my apache website, with this kind of rules :
For a client which asks (HTTP GET) this url :
http://myserver/img123.jpg
If the file img123.jpg exists in my folder /var/images/, the server returns it. If it doesn't exist, it returns the default file which is in the root directory : /imgdefault.jpg
The following rule works if the file exists in the root directory (as the defa开发者_运维百科ult one), but I'd like to check it in another absolute folder.
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^img.*\.jpg$ /imgdefault.jpg
I'm pretty sure it's possible .... but I don't know rewritecond rules enough
You need to use the correct path like:
RewriteCond %{DOCUMENT_ROOT}/var/images/$0 -s
RewriteRule ^img.*\.jpg$ var/images/$0
精彩评论