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 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿