How to make non-existent (404) pages redirect to index?

Discussion in 'HTML & Website Design' started by easydolla, Oct 2, 2008.

  1. #1
    I know you need to set up .htaccess file, but don't know what to put in it.

    I want to make it so somebody goes to mywebsite.com/nonexistentpage, instead of having the default (404 not found) , having it redirect to my own "oops" page or the index page?

    Also what directory would I have to put it in? (I'd guess it'd be public html?)

    Thank you
     
    easydolla, Oct 2, 2008 IP
  2. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #2
    I wouldn't redirect to your index/home page. The visitor would not know there was an error, only that he's not where he thought he would be.

    Make yourself an html page for each error you want to customize and put it into a handy directory, say /error.

    your .htaccess file goes in the document root directory and might include something like this:
    
    ErrorDocument 401 /error/401.html
    ErrorDocument 403 /error/403.html
    ErrorDocument 404 /error/404.html
    ErrorDocument 500 /error/500.html
    Code (markup):
    cheers,

    gary
     
    kk5st, Oct 2, 2008 IP
  3. easydolla

    easydolla Peon

    Messages:
    403
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Oh thanks!

    So your saying, put .htaccess stating "ErrorDocument 404/page_it_redirects_to"?`

    In that case I would have to put .htaccess in every directory right?

    Thank you
     
    easydolla, Oct 2, 2008 IP
  4. kk5st

    kk5st Prominent Member

    Messages:
    3,497
    Likes Received:
    376
    Best Answers:
    29
    Trophy Points:
    335
    #4
    Watch the spaces. It's "ErrorDocument 404", space, then the path to the error page "/error/404.html". (without the quotes)

    You only need the .htaccess file in your document root directory, and it applies to all sub-directories, too.

    cheers,

    gary
     
    kk5st, Oct 2, 2008 IP
  5. easydolla

    easydolla Peon

    Messages:
    403
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks man, I got it!
     
    easydolla, Oct 3, 2008 IP