Custom 404 Page issue in sub folders
I am noticing my 404 page works fine wh开发者_JAVA百科en the wrong address is requesting something on the root level www.mywebsite.com/nopage.html
. But if I am going to a subpage that is not there then my 404 does not show correctly www.mywebsite.com/admin/nopage.html
. Is the only way to do this is set absolute paths to all the style sheets, links and images in your 404?
this is my http.conf entry:
ServerName www.mywebsite.com
DocumentRoot /var/www/currentsite
ErrorDocument 404 /404error.php
<Directory /var/www/currentsite>
Options -Indexes FollowSymLinks +Includes
AllowOverride all
Allow from all
Order allow,deny
</Directory>
Is there a way to send the browser to the 404 page verse calling the 404 down to where ever the user has ended up at?
Add <base href="http://www.mywebsite.com">
to the head
tag of your error page to make all relative urls resolve relative to www.mywebsite.com
(instead of www.mywebsite.com/admin
). I'm assuming that your error page is dynamically generated anyway, so if this error page needs to work on multiple domain names, it shouldn't be hard to add the correct domain name to the page on the server.
In your .htaccess file use complete URL address for your error page path
ErrorDocument 404 http://www.yourdomain.com/404.html
Good Luck!
Just adding some information to Kianoush's answer.
Add the redirect to one 404-Page to all of your .htaccess
files: (root and if every subfolder have an own .htaccess
, then there as well)
ErrorDocument 404 http://www.yourdomain.com/404.html
Further the paths in your 404-Page must be completed:
wrong:
href="../css/style.css"
right:
href="https://www.yourdomain.com/css/style.css"
This must be added for each file, image, etc.. in your 404-Page.
精彩评论