ErrorDocument 404 /404.html
After that, create a file in the root directory of the site
404.html and write in it the code of the page that will be shown on 404 errors.
Similar settings can be made for errors 401, 403.
pagespeedif included optimization settings... To fix the problem, disable optimization settings or not use links with similar keywords.
To customize your 404 error page in popular CMS corresponding instructions are available: