4

I'm using XAMPP with Apache 2.4.18.

My client have 3 divisions of their work (they do 3 different things so they have 3 divisions inside of the website).

So the URL is like this: clientName.domain/workDivisionX

I have this folder structure:

htdocs
L clientName
  L .htaccess
  L workDivision1
    L css
    L img
    L js
    L errors
      L 404.php
      L 500.php
    L //other files
  L workDivision2
    L css
    L img
    L js
    L errors
      L 404.php
      L 500.php
    L //other files
  L workDivision3
    L css
    L img
    L js
    L errors
      L 404.php
      L 500.php
    L //other files

The design between these 3 divisions looks so different that I need to show different style and content in the error documents.

So, if I go to: clientName.domain/workDivision1/asdfghjk (resulting in HTTP 404), I should be able of display the workDivision1's 404 error page. Same with other divisions.

Is there any chance to show the ErrorDocument base on the division folder? Not necessarily must be done through htaccess. I'm open to alternatives.

1

One way to do this is to simply define a separate ErrorDocument for each directory. Either create a .htaccess file in each subdirectory with the appropriate directive, or use <Directory> containers in your server config.

For example, in htdocs/clientName/workDivision1/.htaccess:

ErrorDocument 404 /clientName/workDivision1/errors/404.php

etc.

  • 1
    Hi, @w3dk Totally worked. I didn't know that I can have custom . htaccess files inside folders, I thought it was a unique file just for the root. Thank you very much! – Jimmy Adaro Oct 20 '16 at 20:00
  • Generally... you can have .htaccess files (aka per-directory Apache config files) anywhere along the filesystem path. The file in the lowest subdirectory (ie. the most "specific") will generally take priority, but there is also a certain amount of "inheritance" that goes on (depending on the module). However, it is not good practice to have many .htaccess files as it can get confusing and hard to maintain. Often preferable to have just one in the document root (as you suggest), but for something like this it is OK. – MrWhite Oct 20 '16 at 22:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.