Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jun 2008
    Thanked 0 Times in 0 Posts

    Redirect Any 404 Errors Within Folder

    Hi everyone,

    How would I go about redirecting 404 errors within specific folders using htaccess?

    For example, let's say I have the folder structure like this:

    site.com/goat/ <= this page exists
    site.com/goat/page/ <= this page exists
    site.com/goat/404/ <= this page does NOT exists

    If someone were to navigate to site.com/goat/404/ (or any page for that matter that doesn't exist within the /goat/ main directory), how would I go about redirecting them to the main /goat/ directory?

    So if you visit an actual page that exists within /goat/ you see the page as normal. However, if you visit a url within /goat/ that returns a 404, you get redirected back to the main /goat/ root.

    Any ideas?

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Saskatoon, Saskatchewan
    Thanked 2,662 Times in 2,631 Posts
    Use an error document instruction:
    ErrorDocument 404 /goat/
    I don't believe there is an easy way to determine where you go beyond this. You could probably specify a base directory and use multiple .htaccess files if you wanted to do something different for each sub-directory.


    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts