简体   繁体   中英

htaccess not redirecting to custom 404 page

I have a custom 404 page called 404page.php , and I have the htaccess file with the line that I found should work (this is the only line I have in the .htaccess file)

ErrorDocument 404 /404page.php

It was working fine yesterday, but today I was optimizing images and some other stuff on the website, and when I reuploaded it, the htaccess didn't redirect to 404page.php anymore, but to a page that has this written:

Not Found

The requested URL /asfsdtg was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

(I just typed asfsdtg to test if it was working).

The website is uploaded online and I'm managing it through cpanel (I'm still a beginner). I searched for some solutions, I tried adding another line to .htaccess, then it looked like this:

RewriteEngine on
ErrorDocument 404 /404page.php

I even tried putting the location of the 404page.php as a local link, and the internet link, and it still gave me the weird error page.

Does anyone have some idea whats happening? If you need more info that I didn't supply please tell me what more I can supply

Try out this:

RewriteEngine on
ErrorDocument 404   http://yoursitename.com/404page.php

And be sure that 404page.php exists on the root of your server and is trully called 404page.php not 404Page.php

Be carefull at the characters, this is key sensitive!

Try with like this:

RewriteEngine on
ErrorDocument 404   http://www.sitename.com/404.php

Make to handle any 404 errors.

ErrorDocument 404 /404page.php

If above setting does not works you have to write addition line of code as mentions below. Which identifies for non existing files and directories and redirect to 404.

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ - [R=404,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM