【发布时间】:2015-04-14 22:18:49
【问题描述】:
我有一个 .htaccess 文件,如果子域为 img0.example.info、img1.example.info、img2.example.info 等,则该文件应强制仅提供图像文件。我想在 404.html 中提供带有 404 响应代码的描述性标记,但它只是显示 500 Internal Server Error 错误。
这是我的 .htaccess 文件的内容:
<IfModule mod_rewrite.c>
RewriteEngine on
# If request is via an image subdomain, throw error 404 for any file types other than images
RewriteCond %{HTTP_HOST} ^img[0-9]+\.example\.info$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|gif|png)$ [NC]
RewriteRule ^(.*)$ - [R=404,L]
ErrorDocument 404 /404.html
</IfModule>
它部分适用于 .jpg、.jpeg、.gif 和 .png 文件都可以正常提供服务,但我无法收到整洁的 404 消息。请帮忙。
【问题讨论】: