4

I've made a subsite which runs under example.com/subsite - ideally from an architecture point of view it would be under a subdomain, but we wanted the links to come back to the main domain.

The sub site has a completely different design, and layout, and has a 404 page that is in keeping with the rest of it.

How can I set the 404 for the /subsite subdirectory, without affecting the root domains 404 settings in the .htaccess file.

1 Answer 1

5

Very simple. Just create another .htaccess file in the /subsite directory, and set your ErrorDocument 404 in it to the subsite's 404 page, ie ErrorDocument 404 http://example.com/subfolder/alternate-404.html. The .htaccess in the parent folder will still be used for the main document root, and all other subfolders.

1
  • Generally, you shouldn't be using an absolute URL as the document target in the ErrorDocument directive as this will result in a 302 external redirect (not a 404). You should be using a root-relative URL-path, eg. ErrorDocument /subfolder/alternate-404.html.
    – MrWhite
    Commented Dec 26, 2020 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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