Redirects instead of the default 404 page

Discussion in 'PHP' started by mringuk, Oct 25, 2008.

  1. #1
    I'm still learning to use PHP and would like to add an action to my present PHP re-direct coding. If the required file can't be found I would like an action which could possibly search the files in the web directory and when the script does not find the requested files or pages it re-redirects instead of the default 404 page. Can anyone show me, if it's possible, how it's done.
     
    mringuk, Oct 25, 2008 IP
  2. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    look into .htaccess
     
    Kyosys, Oct 25, 2008 IP
  3. science23

    science23 Active Member

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    91
    #3
    redirect via .htaccess

    create a .htaccess file:
    
    ErrorDocument 404 http://www.yourdomain.com/404page.php
    
    Code (markup):

    // science
     
    science23, Oct 25, 2008 IP
  4. Calon

    Calon Peon

    Messages:
    25
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    It really depends on what webserver you're using, .htaccess is only for Apache.

    If you're using Apache then just use the htaccess code that science created for you.

    I got that from a website, I can't paste the link because of my user level, so don't credit me.
     
    Calon, Oct 25, 2008 IP
  5. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #5
    you can still paste links without http:// and www.
     
    Kyosys, Oct 26, 2008 IP
  6. mringuk

    mringuk Peon

    Messages:
    11
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks everyone. Cracked it with the .htaccess file directing it to my own error page. Tip: It didn't work when creating the .htaccess file in Notepad but did when using WordPad.

    Thanks again.
     
    mringuk, Oct 26, 2008 IP
  7. Chios

    Chios Well-Known Member

    Messages:
    1,740
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    195
    #7

    WordPad instead of Notepad Working ??
    That is totally absurd

    but since you got it working, that is what matters !!!!!!
     
    Chios, Oct 26, 2008 IP
  8. SEOAnalytic.com

    SEOAnalytic.com Member

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #8
    You should use the right encoding when using editors such as wordpad. i don't remember which one :)
     
    SEOAnalytic.com, Oct 26, 2008 IP
  9. SEOAnalytic.com

    SEOAnalytic.com Member

    Messages:
    106
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #9
    Oh, i think ANSI
     
    SEOAnalytic.com, Oct 26, 2008 IP