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.
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.