How to Redirect 404 to Homepage in PHP using .htaccess

Whenever you’re facing a 404 error, it is frustrating when you’re the owner of the website. Site owners have to worry about the same 404 error that occurs when the user visits your site.

With these types of errors occurring continuously, you will lose your site traffic.

This article will help you to redirect to the Homepage if you faced 404 errors on your website. Also, it will help you not to lose your website traffic.

How to Redirect 404 to Homepage in PHP using .htaccess

Whenever you’re running the website, it is good to know to redirect 404 to the Homepage. Here are the steps to redirect your website from 404 to Homepage,

1. Open .htaccess file

Login to your cPanel account.

Goto File manager -> public_html -> .htaccess

Make sure you have enabled the hidden files.

2. Redirect 404 to Homepage using .htaccess

Add the below code in your .htaccess file to redirect all your 404 errors to your website Homepage.

ErrorDocument 404 http://Your URL

Replace “Your URL” with your domain Home page URL to redirect to the website Homepage.

Also, you can redirect all 404 errors to the specific webpage. Replace “Your URL” with your specific URL. The site will redirect to the specific URL you have mentioned.