Redirecting 404 [Not Found] Error To Homepage And

2019-08-18 03:15发布

问题:

I googled and searched on stack over flow but i not found my answer. in Google webmaster Tools, My site have 58,842 Not Found[404] URL Errors. I want all 404 pages redirect to home page with 410 status code using the .htaccess file. I mean before redirecting to home page, I want visitors or Search Engines redirected to home page and get 410 status code. I want tell to Search Engines that, the 404 page was permanently deleted[410] and redirect to home page. For example...

step-1 Visitors or Search Engines visits this url. this is 404 page.
https://example.com/some-url-of-my-blog

step-2 Search Engines get HTTP/1.1 410 Gone [status code 410]
step-3 Visitors or Search Engines redirected to home page. That's it.

Is it possible in .htaccess file. Please anyone solve this.

回答1:

It sounds like you are really just wanting the 410 redirect on any pages and directories that do not exist.

For most cases something like this should work fine

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ / [L,R=410]