doudi8519 2017-05-25 13:53 采纳率: 100%
浏览 28
已采纳

htaccess重定向将所有url重定向到page.php

I need advise on to 301 permanent redirect using htaccess all pages having ?page=9 with index.php

Can anyone guide on how to achieve desired

For example -1

http://www.example.com/?page=9&option=com_news&view=list&Itemid=100&limitstart=840

to

http://www.example.com/index.php&option=com_news&view=list&Itemid=100&limitstart=840

or say for example 2

http://www.example.com/?page=17&option=com_news&view=list&Itemid=100

to

http://www.example.com/index.php&option=com_news&view=list&Itemid=100

Edit Used

RewriteEngine on

RewriteCond %{THE_REQUEST} \?page=.+&(.+)\sHTTP [NC]
RewriteRule ^ /index.php&%1? [L,R=301]

But it dint worked as output is

http://www.example.com/index.php&limitstart=840
  • 写回答

2条回答 默认 最新

  • dongmiao4733 2017-05-25 14:40
    关注

    Assuming you actually want /index.php?option=... rather than /index.php&option=... - just matching on the querystring:

    RewriteEngine On
    RewriteCond %{QUERY_STRING} page=[^&]+&(.*) [NC]
    RewriteRule .* /index.php?%1 [L,R,QSD]
    

    However if you really do want /index.php&option=... replace the RewriteRule with:

    RewriteRule .* /index.php&%1 [L,R,QSD]
    


    Note: either way, this may not work as expected if page is not the first paramter


    If your Apache version is older than 2.4 replace the RewriteRule with:

    RewriteRule .* /index.php?%1? [L,R]
    

    The [QSD] flag was only introduced with 2.4 - shouldn't be necessary anyway since the entire querystring is being matched.

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

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测