dongzhang1839 2016-06-08 21:53
浏览 30

php vs htaccess重定向

I'm looking for a detailed explanation of PHP redirect vs htaccess redirect. Question is already asked here but my scenario is little different than that.

I have an old site lets say www.mydomain.com/oldsite/ And my new site is www.mydomain.com/newsite/

This is a wordpress installation on /oldsite and there are so many posts and writing all of them in htacccess is very lengthy process so if I just put a php code in header.php of theme before any html output which will redirect page to new address is it a good practice or should I switch to htaccess. Code I'm using is

if (is_singular('post')){

 $link = get_the_permalink();
 $new_link = str_replace("oldsite","newsite",$link);

 header("HTTP/1.1 301 Moved Permanently"); 
 header("Location:".$new_link); 
 exit();

}

URL structure on /newsite is bit different than /oldsite and I'm handling all posts and archives redirection with php after appending the URL structure changes in string before php redirection.

  • 写回答

1条回答 默认 最新

  • duanmei1894 2016-06-08 21:59
    关注

    There's no real functional difference. Apache with a .htaccess and PHP will both issue a 301 header redirect. Neither is better (or even a "best practice") redirect over the other. At the end of the day, a header is a header.

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题