Redirect all 404 pages using .htaccess [code]

To redirect all 404 (Not Found) errors to a custom page using .htaccess, you need to use the ErrorDocument directive.

Here’s how you can do it:

Create a custom 404 page: Make a new HTML or PHP file that will serve as your 404 error page. For example, let’s call it 404.html.

Modify your .htaccess file: Add the following lines to your .htaccess file, which is typically located in the root directory of your website.

ErrorDocument 404 /404.html

Here’s a step-by-step guide:

  1. Access your .htaccess file:
    • If you’re using an FTP client, navigate to the root directory of your website.
    • If you’re using a control panel like cPanel, use the File Manager to locate the .htaccess file.
  2. Edit the .htaccess file:
    • Open the .htaccess file in a text editor.
    • Add the line: ErrorDocument 404 /404.html
    • Save the changes.
  3. Create the custom 404 page:
    • In your website’s root directory, create a new file named 404.html.
    • Add your custom HTML content for the 404 error page.
    • Save the file.