duanlu6268 2014-11-25 13:35
浏览 90
已采纳

创建301重定向多个URL地址相同的服务器?

Lets take for example the image bellow. The issue is that 3 url addresses are pointing to the same server, and I need to create a 301 redirect from one to another mostly for SEO reasons. But I can't do it in the htaccess because it created a infinity loop for one of those domains, I also try something like this::

 if ($do_redirect !== '' && trim($do_redirect,'/') !== trim($userrequest,'/')) {
       if (strpos($do_redirect,'/') === 0){
            $do_redirect = home_url().$do_redirect;
       }
        header ('HTTP/1.1 301 Moved Permanently');
        header ('Location: ' . $do_redirect);
        exit();
  }

But in theory this should had work, but when I did checked such domain with curl -I domain.com I get:

HTTP/1.1 200 OK
Date: Tue, 25 Nov 2014 13:33:49 GMT

instead of:

HTTP/1.1 301 Moved Permanently
Date: Tue, 25 Nov 2014 13:33:04 GMT

Any ideas?

enter image description here

  • 写回答

1条回答 默认 最新

  • doufu5401 2014-11-25 14:05
    关注

    The best solution is to do this on the Apache end.

    <VirtualHost *:80>
            ServerName   sample.org
            Redirect 301 / http://www.newdomain.com/
    </VirtualHost>
    

    Apache will issue the 301 with less overhead this way. If you can't do that, the PHP solution looks like

    if($_SERVER['HTTP_HOST'] == 'sample.org') {
        header ('HTTP/1.1 301 Moved Permanently');
        header ('Location: http://www.newdomain.com/');
        exit();
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 三极管1000倍放大电路
  • ¥15 vscode报错如何解决
  • ¥15 前端vue CryptoJS Aes CBC加密后端java解密
  • ¥15 python随机森林对两个excel表格读取,shap报错
  • ¥15 基于STM32心率血氧监测(OLED显示)相关代码运行成功后烧录成功OLED显示屏不显示的原因是什么
  • ¥100 X轴为分离变量(因子变量),如何控制X轴每个分类变量的长度。
  • ¥30 求给定范围的全体素数p的(p-2)/p的连乘积值
  • ¥15 VFP如何使用阿里TTS实现文字转语音?
  • ¥100 需要跳转番茄畅听app的adb命令
  • ¥50 寻找一位有逆向游戏盾sdk 应用程序经验的技术