homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / WebmasterWorld / Webmaster General
Forum Library, Charter, Moderators: phranque

Webmaster General Forum

Custom 404 page for sub directories
How does a custom 404 message work for subdirectories

Msg#: 4624761 posted 11:34 am on Nov 20, 2013 (gmt 0)

Howdy experts

I want to set up a custom 404 page in the root of the site and for selected sub directories as the example below illustartes

www.webshop.com - "general 404" page
www.webshop.com/shoes - "shoes 404" page
www.webshop.com/pants - "pants 404" page

First of all is this possible and how would it work? Will the subdirectory 404 for shoes be shown only if a user is clicking a broken link that used to belong in the shoes subdirectory like www.webshop.com/shoes/brokenlink.htm? Or could you also set it up so a user would get the shoes 404 page if he follows a broken link from a page in the /shoes subdirectory

Do you have any other thoughts about custom 404 for sub directories pro/con.

I hope the above makes sense.




WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

Msg#: 4624761 posted 12:55 pm on Nov 20, 2013 (gmt 0)

Are you on Apache? Either in .htaccess or in <Directory> sections of the config file, put an

ErrorDocument blahblah

line in each directory where you want it to be different. You can't have <Directory> sections in htaccess, so you would have to make additional htaccess files for any subdirectories with rules of their own. Anything in a deeper directory overrides anything further up the line. (Except for mod_rewrite, almost everything in Apache behaves this way.)

The choice of ErrorDocument is determined by the URL of the not-found file. If you want something more complicated-- like a document determined by the referer rather than the URL itself-- you would have to create a dynamic error document. Make a single php-or-equivalent page in a single location, and code it to deal with any variables you want it to deal with. You would also need to do something fancier if your directories don't physically exist but are created by rewriting from, say, one central index.php page.

But for normal purposes, a static document is all you need. Note that the physical location of the error document itself doesn't matter. You can have a /shoes-errors.html and a /pants-errors.html and a /codpiece-errors.html all living side by side in the same directory. (Mine's called /boilerplate/, because I have no imagination.)

Reminder! An error document is a special kind of rewrite; the user's browser "thinks" it's at the originally requested URL. So if the error document uses any external files such as css, make sure all links are absolute.

Global Options:
 top home search open messages active posts  

Home / Forums Index / WebmasterWorld / Webmaster General
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved