apache/mod_rewrite 从定义的文件夹中返回现有文件(如果存在),否则返回默认文件
我想为我的 apache 网站编写一个 .htaccess ,具有以下规则:
对于请求(HTTP GET)此网址的客户端:
http://myserver/img123.jpg
如果文件 img123.jpg 存在于我的文件夹 /var/images/ 中,服务器返回它。 如果不存在,则返回根目录中的默认文件: /imgdefault.jpg
如果文件存在于根目录中(作为默认目录),则以下规则有效,但是我想在另一个绝对文件夹中检查它。
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^img.*\.jpg$ /imgdefault.jpg
我很确定这是可能的......但我不太了解 rewritecond 规则
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 default 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要使用正确的路径,例如:
You need to use the correct path like: