301重定向任何不存在的图像,PDF或URL使用的.htaccess [英] 301 Redirects on any non existent image, pdf or url using .htaccess

查看:128
本文介绍了301重定向任何不存在的图像,PDF或URL使用的.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不断更新的网站,问题是,当一个图像不存在了的谷歌机器人的索引网站提供了大量的五百分之四百○四错误或已被删除。这是一个产品目录的网站,让产品被删除,并添加上一个小时计算。

I have a website that is constantly updated and the problem is that the Google bot that indexes the website gives a lot of 404/500 errors when a image does not exist anymore or has been deleted. It's a product catalogue website, so products get deleted and added on a hourly basis.

我已经试过这种重写规则

I've tried this RewriteRule

^/(.*)$ /site/page/view/404 [R=301,L]

这将导致该网站上的所有图像不显示更多或

which causes all images on the website not to display any more or

^(.*) /site/page/view/404 [R=301,L] 

这只是给出错误500浏览器。

which just gives error 500 on the browser.

有没有一种方法,以配合不存在的文件/ URL,并永久重定向到不同的URL,例如 /网站/网页/浏览/ 404

Is there a way to match non existent files/urls and redirect them permanently to different url e.g. /site/page/view/404

推荐答案

试试这个的(假设的.htaccess 是Web根)

Try this (assuming .htaccess is in web root)

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d   # not a dir    
RewriteCond %{REQUEST_FILENAME} !-f   # not a file
RewriteRule ^.*$ /site/page/view/404 [R=301,L]

另外,你可以使用的ErrorDocument

ErrorDocument 404 /site/page/view/404

这篇关于301重定向任何不存在的图像,PDF或URL使用的.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆