简体   繁体   中英

404 customisation

I want to make a custom 404 page.

I created a .htaccess containing only this line :

ErrorDocument 404 /errors/404.html

And the structure of my website is like this :

  • errors
    • 404.html
  • index.php
  • .htaccess
  • includes
    • header.html

I always get this erros on the 404 page :

Not Found

The requested URL /blabla/bg was not found on this server.

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

An idea ? Thank you !

My guess is that your document root is not equivalent to where your .htaccess is. Unfortunately, ErrorDocument is not relative to where your .htaccess is and instead bases the path on where your document root is (for instance /var/www/ )

One (kind of hacky) solution I've used in the past to get "relative" 404 Error pages is to do the following:

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

The other (and more correct way) to do this is to specify the entire path from the true document root on your server.

To get this full path you'll want to open the 404 page in a browser (and make it a php page in your case so you can get this variable out: $_SERVER['SCRIPT_NAME'] or if you happen to have more knowledge of the setup of your directory structure. You can base it off of $_SERVER['DOCUMENT_ROOT']

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