How to redirect to a different URL

This question already has an answer here:

  • How to make a redirect in PHP? 27 answers

  • Write header like:

      header("Location: http://www.testing.com"); 
    

    on the home page of http://www.testing.com/newsite

    for more about header


    So simply add below line at index page.

    header("Location: http://www.testing.com", false, 301);
    exit;
    

    Or write it in common file that are included in every page.

    make sure there is http:// in header location other wise it will look for directory.

    And also put exit; at the end so other code will not execute.

    because sending header will not terminate script execution.

    --EDIT-- it should be 301 to make it last forever


    If you have a directory /newsite then place a .htaccess inside that directory with:

    RewriteEngine On
    RewriteRule ^.*$ http://www.newsite.com/ [R=301,L] 
    

    However if you directed the newsite.com into the /newsite directory, then you need what Sankalp Mishra wrote in his answer. (but with newsite instead of testing)

    Options +FollowSymLinks
    RewriteEngine On
    RewriteRule ^newsite$ http://www.newsite.com/ [R=301,L]
    
    链接地址: http://www.djcxy.com/p/34704.html

    上一篇: 重定向站点中的所有链接以重定向页面

    下一篇: 如何重定向到不同的URL