Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2008
    Location
    Jupiter
    Posts
    49
    Thanks
    8
    Thanked 0 Times in 0 Posts

    301 redirect with php

    Anyone have any personal recommendations on how to do this? I searched online and saw that there are lots of ways to do it so im confused on which route to take.

  • #2
    Regular Coder devinemke's Avatar
    Join Date
    Dec 2004
    Location
    NYC
    Posts
    443
    Thanks
    0
    Thanked 12 Times in 11 Posts
    PHP Code:
    header('location: http://www.example.com');
    exit(); 

  • #3
    eak
    eak is offline
    Regular Coder eak's Avatar
    Join Date
    Jun 2002
    Location
    Nashville, TN
    Posts
    354
    Thanks
    0
    Thanked 26 Times in 26 Posts
    devinemke, that code does a 302 redirect, not a 301.

    tokio, this is what I use:
    PHP Code:
    function redirect$url$permanent false ){
        if( 
    parse_url$url ) !== parse_url$_SERVER['REQUEST_URI'] ) ){
            if( 
    $permanent === true ){
                
    header("HTTP/1.1 301 Moved Permanently");
                
    header('location: ' $urltrue301 );
            } else {
                
    header('location: ' $url );
            }
            exit;
        }
        return 
    false;

    By default, the redirect is not permanent.
    To make it a 301 redirect, set the second argument to true.
    Last edited by eak; 05-06-2009 at 03:50 PM.
    eak | "Doing a good deed is like wetting your pants; every one can see the results, but only you can feel the warmth."


  •  

    Posting Permissions

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