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 ;)

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

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看