dongyan7172 2015-03-31 13:30
浏览 43
已采纳

Mod重写动态路径(无查询)

I am trying to create redirects to content on my old site in the form of:

domain.com/fiction/UNIQUE/book to sub.domain.com/fiction/UNIQUE/book

Not all pages on domain.com should redirect to sub.domain.com. Just the ones that contain /fiction/. UNIQUE is a dynamically generated ID.

So this should be simple to check for the existence of domain.com/fiction/ and replacing with sub.domain.com/fiction/ then adding the rest of the string /UNIQUE/book.

I have looked at Mod Rewrite and posts with QUERY_STRING, but my understating is limited and this appears to only be applicable with ?query style dynamically generated pages.

Thanks for any help.

  • 写回答

2条回答 默认 最新

  • dongying6659 2015-03-31 13:37
    关注

    You can use this code for your htaccess file:

    RewriteCond %{HTTP_HOST} ^.+$
    RewriteRule ^(fiction/.*)$ http://sub.%{HTTP_HOST}/$1 [L,R=301]
    

    http://domain.com/fiction/UNIQUE/book will get redirected to http://sub.domain.com/fiction/UNIQUE/book. http://domain.com/scifi/UNIQUE/book will not be modified.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试