duanlan8763 2013-03-14 00:10
浏览 100
已采纳

htaccess重定向 - 更改URL的查询部分

Google picked up the following URL and ranked it:

http://www.example.com/yyy/zzz-99.php?item_id=99&sort=1 (the item_id=99 part should not be there).

Since I picked up the error and fixed it, I have added the following line to my htaccess:

RedirectPermanent /yyy/zzz-99.php?item_id=99&sort=1 http://www.example.com/yyy/zzz-99.php?&sort=1

However that redirect does not work. Any clue on what i am doing wrong?

  • 写回答

3条回答 默认 最新

  • douxieti6851 2013-03-14 00:29
    关注

    I think you need mod_rewrite to achieve even that single replacement, because includes a query string.

    You may try this in the .htaccess file in root directory, provided mod_rewrite is enabled:

    Options +FollowSymLinks -MultiViews
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_URI}   ^/yyy/zzz-99\.php  [NC]
    RewriteCond %{QUERY_STRING}  item_id=99&sort=1  [NC]
    RewriteRule .*        /yyy/zzz-99.php?&sort=1?  [NC,L,R=301]
    

    Redirects

    http://www.example.com/yyy/zzz-99.php?item_id=99&sort=1 to

    http://www.example.com/yyy/zzz-99.php?&sort=1

    For silent mapping, remove R=301 from [NC,L,R=301].

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

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器