Redirecting 404 [Not Found] Error To Homepage And Before Redirecting To Home Page, Tell Search Engines 404 Page is Gone[410] Using .htaccess

拟墨画扇 提交于 2019-12-25 03:46:24

问题


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]


来源:https://stackoverflow.com/questions/53447528/redirecting-404-not-found-error-to-homepage-and-before-redirecting-to-home-pag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!