duanba8173 2019-04-18 15:34
浏览 64

使用键值重定向PHP URL

I am trying to redirect a url with php key values to a different domain.

The site is being deprecated so I tried a simple redirect by hard coding the URL but could not get that to succeed.

I have also tried using RewriteCond using QUERY_STRING and RewriteRule. I found success using only 1 key value here but when I tried using multiple key values, it does not pick up the second key and causes the redirect to fail.

RewriteCond %{QUERY_STRING} (|&)key1=value1($|&)

RewriteCond %{QUERY_STRING} (|&)key2=value2($|&)

RewriteRule (.*) https://www.example.com/new/path [L,R=301]

Expected result: example1.com/sample.php?key1=value1&key2=value2 --> example2.com/new/path

  • 写回答

1条回答 默认 最新

  • duanchendu69495 2019-04-18 16:05
    关注

    You need to use a single RewriteCond to check your querystring before redirecting to the new site .

    RewriteEngine on
    
    RewriteCond %{QUERY_STRING} (^|&)key1=value1&key2=value=2($|&) [NC]
    RewriteRule ^/?sample\.php$ https://www.example.com/new/path?  [L,R=301]
    

    The empty question mark ? at the end of the destination path is important as it discards the old querystring from new url otherwise if it removed then your new url will look something like example.com/new/path?key1=value1&key2=value2 .

    Make sure to clear your browser cache before testing this new rule.

    评论

报告相同问题?

悬赏问题

  • ¥15 STM32无法向设备写入固件
  • ¥15 使用ESP8266连接阿里云出现问题
  • ¥15 BP神经网络控制倒立摆
  • ¥20 要这个数学建模编程的代码 并且能完整允许出来结果 完整的过程和数据的结果
  • ¥15 html5+css和javascript有人可以帮吗?图片要怎么插入代码里面啊
  • ¥30 Unity接入微信SDK 无法开启摄像头
  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并