dongqiu8375 2013-08-07 13:24
浏览 79
已采纳

如何使用.htaccess 301重定向和更改URL?

I just discovered that I have some duplicate pages that I need to remove but some pages that should not exist are indexed and generating small amounts of traffic. I want to redirect those urls to the original ones.

http://www.example.com/buy-something.php

to

http://www.example.com/something.php

I basically need to remove the "buy-" in the urls and make sure the page is redirected to the proper page. Here is what I have so far:

#301 Redirect buy- to none
RewriteRule ^([a-zA-Z\.]+).php$  /buy-$1.php  [L,R=301]

But this does nothing to the pages that should be redirected and adds a loop of buy-buy-buy-buy-buy-buy- to other pages and causes them to time out. I have tried a few other variations but to no prevail.

Your help is greatly appreciated.

  • 写回答

2条回答 默认 最新

  • douqian8238 2013-08-07 13:32
    关注

    You mixed up the syntax, right now you are redirecting any .php to /buy-.php, since you want it the other way arround try:

    RedirectRule ^buy-([a-zA-Z\.]+).php$  /$1.php  [L,R=301]
    

    That should take any buy-*.php domains and redirect them to *.php with the Code 301.

    Source: http://httpd.apache.org/docs/current/mod/mod_rewrite.html

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

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么