如何将错误的网址重定向到错误页面

Hello guys i am building up a project in php and facing issues regarding the wrong url my actual url is like this http://localhost/blog_dir/blog/top-of-the-world so when i am hitting to this url i can see the actual page that i want to see but when i am typing a wrong url like http://localhost/blog_dir/blog/top-of-the-w it shows me error like the notices, warnings and all the common errors of php into that page which is quite obvious as it is not getting the proper url. So what do i want to do is that if any user types wrong url then they must get redirected to the error page that i have created which is err.php. One more thing i would like to add is that the problem arises i think is due to the codes that i have written in my .htaccess. So i am adding up my .htacces code here

RewriteEngine On 
ErrorDocument 404 http://localhost/blog_dir/err.php

#RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^blog/([^/\.]+)?$ blog-de.php?post=$1 [L,QSA]

我希望你能帮助我完成我的项目。

评论
  • 为你痴迷
    为你痴迷 回复

    这可以解决您的问题:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . / [L,R=301]
    
    ErrorDocument 404 path_to_error_page
    
    注意:将path_to_error_page替换为错误页面的路径。