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 相信营销号手欠改了处理器设置
  • ¥15 时间序列LSTM模型归回预测代码问题
  • ¥50 使用CUDA如何高效的做并行化处理,是否可以多个分段同时进行匹配计算处理?目前数据传输速度有些慢,如何提高速度,使用gdrcopy是否可行?请给出具体意见。
  • ¥15 基于STM32,电机驱动模块为L298N,四路运放电磁传感器,三轮智能小车电磁组电磁循迹(两个电机,一个万向轮),如何通过环岛的原理及完整代码
  • ¥20 机器学习或深度学习问题?困扰了我一个世纪,晚来天欲雪,能饮一杯无?
  • ¥15 c语言数据结构高铁订票系统
  • ¥15 关于wkernell.PDB加载的问题,如何解决?(语言-c#|开发工具-vscode)
  • ¥15 (标签-STM32|关键词-智能小车)
  • ¥20 关于#stm32#的问题,请各位专家解答!
  • ¥15 (标签-python)