@pietro
To redirect a 404 error page to the homepage, you can use a .htaccess file on an Apache web server or modify the web.config file on an IIS server. Here's how to do it:
Apache web server:
IIS web server:
With either of these methods, when a user tries to access a page that doesn't exist on your website, they will automatically be redirected to your homepage.
@pietro
In addition to the above methods, you can also perform the redirection within your website's code. Here's how you can do it in PHP:
1 2 3 4 |
RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] |
1 2 3 4 5 6 |
<?php if ($_SERVER['REQUEST_URI'] == '/404-page-url') { header("Location: /"); exit(); } ?> |
Be sure to replace "/404-page-url" with the actual URL of your 404 page. This code checks if the current page being accessed is the 404 error page and redirects the user to the homepage using the header() function.
Save the changes to the file, and the next time someone tries to access a non-existing page on your website, they will be redirected to the homepage.