How to redirect 404 error to homepage with .htaccess?

Hi, how do I redirect a 404 error to my .htaccess homepage?

Example: site.com , if you write site.com/some_site_notforund instead of 404, it redirects us to the main page

Example 2:
sadistic.pl , if you write sadistic.pl/some_site_notfound instead of 404, it redirects us to the current page

+5
source share
5 answers

Try:

FallbackResource /index.html

or whatever is on the main page


to try:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.html [L]
+10
source

,

.htaccess:

ErrorDocument 404 /404.php

, , 404.php.

404.php :

<?php
    header('location:index.php');
?>

, , , 404.php index.php

+4

.htaccess:

ErrorDocument 404/index.php

+3

. , 404 , URL,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.html [L]
+2
  • .htaccess .
  • RewriteRule.

    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ http://127.0.0.1/dir/index.php [L]

.

+2

Source: https://habr.com/ru/post/1527820/


All Articles