ds0678 2017-04-05 14:09
浏览 31
已采纳

将一个TLD +单个目录的所有页面重定向到另一个TLD的根目录

In Redirect all pages of one TLD to another there's a clear example of how to Redirect from the root of one TLD to the root of another TLD. But I want add a Rewrite Condition & Rule to my .htaccess file that will do the following redirects...

www.example.com/one  -->  www.example.co.uk
www.example.com/one/two  -->  www.example.co.uk/two
www.example.com/one/two/three  -->  www.example.co.uk/two/three

So basically it will redirect the URL to one where the TLD is changed and the first directory in the path (/one) is removed.

  • 写回答

1条回答 默认 最新

  • dongzhengzhong1282 2017-04-05 14:32
    关注

    So something like this should be in your vhost for www.example.com

     RewriteEngine On
     RewriteRule ^/one(.*) www.example.net/$1 [R=301,L]
    

    R=301 causes the browser to cache the answer and send the next request to that target directly to the according URL. So clear your cache while testing ;)

    Or, if you don't want to see the requestor that he is being redirected:

     RewriteRule ^/one(.*) www.example.net/$1 [P,L]
    

    Which requires the mod_proxy module to be activated.


    One a sidenote: plz use example.com in examples, because domain can't be used ;)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1