View Full Version : Redirect Any 404 Errors Within Folder

09-13-2011, 11:37 PM
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?

09-15-2011, 09:22 PM
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.