301 Redirects on any non existent image, pdf or ur

2019-08-30 23:45发布

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] 

which just gives error 500 on the browser.

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

标签: .htaccess
1条回答
We Are One
2楼-- · 2019-08-31 00:17

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]

Alternatively, you can use ErrorDocument as well.

ErrorDocument 404 /site/page/view/404
查看更多
登录 后发表回答