301 or 302 Redirection With PHP

后端 未结 6 1298
长情又很酷
长情又很酷 2020-12-07 20:04

I\'m considering using the following code during a website launch phase to show users a down for maintenance page while showing me the rest of the site.

Is

6条回答
  •  广开言路
    2020-12-07 20:25

    For a 302 Found, i.e. a temporary redirect do:

    header('Location: http://www.yoursite.com/home-page.html');
    // OR: header('Location: http://www.yoursite.com/home-page.html', true, 302);
    exit;
    

    If you need a permanent redirect, aka: 301 Moved Permanently, do:

    header('Location: http://www.yoursite.com/home-page.html', true, 301);
    exit;
    

    For more info check the PHP manual for the header function Doc. Also, don't forget to call exit; when using header('Location: ');

    But, considering you are doing a temporary maintenance (you don't want that search engines index your page) it's advised to return a 503 Service Unavailable with a custom message (i.e. you don't need any redirect):

    
    
    
    Temporarily Unavailable
    
    
    
       Your message here.
    
    
    

提交回复
热议问题