如何使用.htaccess将错误404重定向到主页?

sss*_*sss 6 .htaccess redirect http-status-code-404 web

您好我如何使用.htaccess将错误404重定向到主页?

示例: site.com如果写入site.com/some_site_notforund而不是404将我们重定向到主页面

示例2:
sadistic.pl如果写sadistic.pl/some_site_notfound而不是404将我们重定向到当前页面

Jon*_*Lin 13

尝试:

FallbackResource /index.html
Run Code Online (Sandbox Code Playgroud)

或者无论主页是什么


尝试:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.html [L]
Run Code Online (Sandbox Code Playgroud)

  • 最好的方法是 - `ErrorDocument 404 /index.php` (2认同)

pur*_*ush 6

你可以这样做

这将是.htaccess文件:

ErrorDocument 404 /404.php
Run Code Online (Sandbox Code Playgroud)

未找到所有页面的页面将显示404.php文件。

404.php文件中,您可以编写:

<?php
    header('location:index.php');
?>
Run Code Online (Sandbox Code Playgroud)

因此,所有未找到的页面页面都将转到404.php页面,并将其重定向到index.php


小智 5

或者保存重新路由步骤并将以下内容放入您的 .htaccess 文件中:

错误文档 404 /index.php