[英]Add status code 410 for missing images in Drupal 6
I need to send status 410 for missing images instead of 404, in Drupal 6. For example I have a image link as https://www.example.com/our-locations/directory/sub-directory/files/xyz.png
which no longer exist in this location, then I need to send status 410 instead of 404. 我需要在Drupal 6中发送状态信息410,而不是404,而不是404。例如,我有一个图像链接,例如
https://www.example.com/our-locations/directory/sub-directory/files/xyz.png
该位置不再存在,那么我需要发送状态410而不是404。
Solutions already I have tried are: 我已经尝试过的解决方案是:
RewriteCond %{REQUEST_URI} ^our-locations/directory/sub-directory/files/(\.jpg|\.png)$ [NC]
RewriteRule ^(.*)$ - [NC,R=410,L]
You can use this : 您可以使用:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} ^/path/.+\.(jpg|png|gif)$
RewriteRule ^ - [R=410,L]
The first condition RewriteCond %{REQUEST_FILENAME} !-f
checks if the the file doesn't exist. 第一个条件
RewriteCond %{REQUEST_FILENAME} !-f
检查文件是否不存在。 Since you want to redirect only 404 images to 410
this condition prevents your other existing files from being redirected to 410. The next condition RewriteCond %{REQUEST_URI} ^/path/.+\\.(jpg|png|gif)$
checks if the uri is /path/image.ext
if both conditions are met then the RewriteRule
is applied. 由于您只想将404图像重定向到
410
因此此条件可防止将其他现有文件重定向到410。下一个条件RewriteCond %{REQUEST_URI} ^/path/.+\\.(jpg|png|gif)$
检查是否如果两个条件都满足,则uri为/path/image.ext
,然后应用RewriteRule
。
You can also use <filesMatch>
and ErrorDocument
directives to catch a 404 image file and then redirect it to a specific page but this will not return the correct error status. 您也可以使用
<filesMatch>
和ErrorDocument
指令来捕获404图像文件,然后将其重定向到特定页面,但这不会返回正确的错误状态。 You can use RewriteRule
instead . 您可以改用
RewriteRule
。
<filesMatch "\.(jpg|png|gif)$">
ErrorDocument 404 http://exmaple.com/410.php
</FilesMatch>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.