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条)

报告相同问题?