404 not found custom page?

Discussion in 'Web Design and Development' started by Macman1993, Jun 12, 2010.

  1. Macman1993 macrumors 6502

    Macman1993

    Joined:
    Nov 23, 2007
    #1
    I wrote a 404 error page and I have been able to redirect to that page but I want to load it inside the current page. I'm not sure how much sense I am making but I want to stay on the same page with the same link but show the content from the notfound.php page. My reason for this is that the page I wrote looks at the link and corrects a common error. I used to have a forum at mysite.com/forum but it was since moved to be on just mysite.com but since people frequently are linked to mysite.com/forum/topic I wrote a php script that will redirect them to mysite.com/topic solving the error without me trying to trace all links and get the authors to fix them.

    For my script to work I need to maintain the url that caused the 404 error but I need my code to be run. So it has to be the same page. I know this is possible because if you go to apple.com/Iamapagethatdoesn'tactuallyexist you get their error page without redirecting. My host has a simple error page editor that keeps you on the page but it only lets you run a .shtml page so my php scripts will not run.
     
  2. -Ryan- macrumors 68000

    Joined:
    Jan 28, 2009
    #2
    How about editing .htaccess file to parse .shtml files as .php if you're not using any other .shtml aside from this one error page? The only difference I can think of is that SSI might not work properly on the shtml page, but I'm sure that won't matter to you if you're wanting to use the page as php anyway.. :)
     
  3. Macman1993 thread starter macrumors 6502

    Macman1993

    Joined:
    Nov 23, 2007
    #3
    I've never tried that and the few tutorials I followed only gave me internal server errors. I used the following code in my .htaccess file

    Code:
    
    <MIME TYPE Extension application/x-httpd-php .html>
    
    used both with and without a space after "php".

    I'm pretty sure that there are other ways of doing this besides changing the parsing.
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    Not sure where you got that .htaccess line from, but it's not right in the least. It would look like this,
    Code:
    AddType application/x-httpd-php .php .shtml
    As far as redirecting errors from .htaccess you would add a line like,
    Code:
    ErrorDocument 404 /error404.html
    And as far as having an old page at a new location, that can also be done via .htaccess. No need to write PHP scripts for it. Here's a partial example. I don't know the exact pieces you need for your site.
    Code:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} /forum [nocase]
    RewriteRule .*$ /topic [last]
     
  5. Macman1993 thread starter macrumors 6502

    Macman1993

    Joined:
    Nov 23, 2007
    #5
    Yea I knew I could do it through .htaccess but I've always prefered writing in php to accomplish things (I'm just weird like that :D) Still would love any ideas to accomplish this though if anyone has ideas.
     

Share This Page