使用htaccess将404错误页面重定向到主页


404 error page redirect to home page using htaccess

我需要将404错误页面重定向到主页。

我使用下面的代码将404页面重定向到主页,但这段代码在一个场景中工作。

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

www.domain.com/slug1这种类型的URL

但是对于www.domain.com/slug1/slug2/slug3 这种类型的url不起作用。

试试这个

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . / [L,R=301]
ErrorDocument 404 /index.php

点击这里获取更多帮助