doujiu8918 2015-09-02 13:35
浏览 39
已采纳

如何.htaccess重定向文件名为新域名的url参数?

I want to be able to redirect url such as subdomain.domain.com/426/long-tail-kw.html to new domain and url such as differentdomain.com/goodname.php?id=long-tail-kw

Also, the number in the url 426 will change often, it could also be 1 or whatever number up to 500

How can I do this in .htaccess file?

Also, the redirect must work with this code that sends the people who come from bing ONLY to the new url. If a person just enters the url then he will not be redirected but when he comes from bing or from whatever specified referrer then he will be redirected.

Thus far I have this code that I used for my old site that had cat-x in the url but I don't know how to change the code to work with only a number in the url instead of cat-x

 RewriteEngine On
 RewriteCond %{HTTP_REFERER} (bing)
 RewriteCond %{HTTP_HOST} ^(?:www\.)?server10\.olddomain\.com$ [NC]
 RewriteRule ^cat-\d+/(.+?)\.html$ http://newdomain.com/go.php?id=$1 [L,QSA,R=302]
  • 写回答

1条回答 默认 最新

  • douduo2407 2015-09-02 14:56
    关注

    Just remove the cat- part:

     RewriteEngine On
     RewriteCond %{HTTP_REFERER} (bing)
     RewriteCond %{HTTP_HOST} ^(?:www\.)?server10\.olddomain\.com$ [NC]
     RewriteRule ^\d+/(.+?)\.html$ http://newdomain.com/go.php?id=$1 [L,QSA,R=302]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持