+4 votes
in Web & Google by (56.5k points)
I found that there are 1000s of 404 pages from my domain  in the google webmaster . Most of those pages are invalid. I don't know how did the google find those pages on my websites. Also, those pages are not there in my sitemap. Anyway, I want to redirect all those invalid pages to either homepage or a designated page e.g my404.html. How can I do that?

1 Answer

+1 vote
by (348k points)
selected by
Best answer

You might have some bad script on your website that might have generated those junk webpages. I also had this issue with my website. Anyway, add the following lines to your .htaccess and it will redirect those gone pages to your desired page. I would recommend to redirect to a page that has really good content.

#redirect all deleted pages to search page
ErrorDocument 404 /yourdesiredpage.html

by (71.8k points)
I would recommend to use the complete URL. I had device detection code in my .httaccess and when I used the above syntax, the redirection went to infinite loop. Using the following syntax solved the redirection issue.

ErrorDocument 404 http://www.example.com/yourdesiredpage.html