dougan7523 2017-01-13 09:02
浏览 60
已采纳

.htaccess重定向到特定路由

I need to redirect a set of specific pages with particular parameters in the URL. I am a bit familiar with .htaccess redirections but this one is giving me a headache.

I want to redirect https://www.xxxxxx.com/index.php?page=shop.ask&flypage=flypage_images.tpl&product_id=182&category_id=39&option=com_virtuemart&Itemid=9

TO: https://www.xxxxxx.com/index.php?page=shop.ask

This is the rule that I have written for redirecting index and index2 but the parameters after "?" are being taken as an OR

RewriteEngine on

RewriteRule index[0-2]*.php?page=shop.(.*)$ https://www.xxxxx.com/index.php?page=shop.ask [R]

I need to escape the '?' as its taking the php as ph or php and the parameters after that are not being taken into consideration by the apache.

I have tried using the REWRITECOND as well using this rule but it doesn't work.

Please suggest the correct redirect rule.

  • 写回答

1条回答 默认 最新

  • doulierong0334 2017-01-13 10:03
    关注

    You need to use the RewriteCond. Try:

    RewriteEngine On
    RewriteCond %{QUERY_STRING} page=shop.ask&flypage=flypage_images.tpl&product_id=182&category_id=39&option=com_virtuemart&Itemid=9
    RewriteRule ^index.php https://www.xxxxx.com/index.php?page=shop.ask [R,L]
    

    This should work as long as your query string always appears in the exact order you specified. Otherwise you'll need to create a bunch of RewriteConds for each parameter in combination with [AND].

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀