SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    Montreal
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP error 404 redirection

    Hi,

    I'm currently using url friendly for my site..... something like this:

    http://domain.com/home

    become

    http://domain.com/?section=home

    Now if someone or a bot change or put something invalid (like abc instead of home), I wish to redirect them to my 404.php page.

    I've got a pre-determinated list of valid section (home product contact, ...) so for the rest, what is the proper, safe and search engine friendly way to redirect them?

    Thank

  2. #2
    SitePoint Enthusiast
    Join Date
    Jun 2008
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can do your url rewriting and custom 404 page in your .htaccess file.

  3. #3
    SitePoint Addict
    Join Date
    Jun 2004
    Location
    Montreal
    Posts
    275
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For sure, but I would primary prefered a php solution... even if more complicated!

  4. #4
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if ( $page not $valid ) {
        
    // Set as an Apache Module:
        
    header'HTTP/1.0 404 Not Found' );

        
    // For CGI:
        
    header'Status: 404 Not Found' );

        include 
    '404.php';
        exit;

    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •