404 Redirect if page not in list

Discussion in 'Apache' started by ian_ok, Apr 16, 2007.

  1. #1
    I'm just trying out some 'free webs space' and you can't use the 404 or 403. A 404 error redirects to the hosts about us page.

    Is there a way with the .htaccess (or other??) to check if the page requested is in a list and if not go to an another file. I only have 6 pages in the website.

    In doing this would it cause any SE problems as I'm not sure a true 404 would be returned.

    I can't use the errordocument404 code

    Cheers Ian
     
    ian_ok, Apr 16, 2007 IP
  2. malayguy

    malayguy Peon

    Messages:
    152
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    0
    #2
    malayguy, Apr 16, 2007 IP
  3. rodney88

    rodney88 Guest

    Messages:
    480
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    0
    #3
    If you have mod_rewrite enabled, you can check if the requested page exists and rewrite to a different file if not.

    Place this in a .htaccess file the root of your domain (domain.com/.htaccess).
    Options +FollowSymLinks
    RewriteEngine On
    RewriteBase /
    RewriteCond %{SCRIPT_FILENAME} !-f
    RewriteCond %{SCRIPT_FILENAME} !-d
    RewriteRule .* 404.php [L]
    Code (markup):
    Change 404.php to whatever 404 error page you want. If you do use a script (PHP or otherwise), you can also send out a 404 response code manually so you don't confuse search engines or anything else relying on the returned status code.

    If you use PHP, you can just put the following at the very top (before any whitespace or output) of the error page and it'll send a 404 header.
    <?php
    header('HTTP/1.0 404 Not Found');
    ?>
    PHP:
     
    rodney88, Apr 16, 2007 IP
  4. ian_ok

    ian_ok Peon

    Messages:
    551
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Still doesn't work, so I guess they have restricted the 404 a lot deeper in order for those errors to still be redirected to their website and not a 404 error page.

    Might have to think about some other code.

    ian
     
    ian_ok, Apr 16, 2007 IP