【问题标题】:Removing the second question mark from URL从 URL 中删除第二个问号
【发布时间】:2012-10-26 06:29:02
【问题描述】:

外部应用使用以下 URL 调用我的网站: http://www.mydomain.com/index.php?route=checkout/success?ref=56

这显然是错误的(因为它有 2 个问号)。

如何编写 .htaccess 重写规则以将第二个问号转换为 ambersand (&) ? (http://www.mydomain.com/index.php?route=checkout/success&ref=56)

我试过了,但它不起作用。

RewriteEngine on
RewriteRule \? \& [L]

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    经过一番研究,我想出了这个

    RewriteCond %{QUERY_STRING} ^(.*)?\?ref=(.*)&?(.*)$
    RewriteRule (.*) /$1?%1&ref=%2%3 [L]
    

    我不知道它是否是最好的,但它确实有效

    【讨论】:

      【解决方案2】:
      RewriteEngine on
      RewriteRule /(.*)?(.*)?ref=(.*)$ /$1?$2&ref=$3  [R]
        RewriteLogLevel 9
      RewriteLog "/var/log/rewrite.log"
      

      必须承认我没有看到它在我的最终工作,但它应该几乎在那里 - 启用重写日志,因此可以更轻松地调试它

      【讨论】:

      • 谢谢,但RewriteRule 出于某种原因无法捕获查询字符串...
      猜你喜欢
      • 2015-06-25
      • 2012-11-27
      • 2015-06-25
      • 1970-01-01
      • 1970-01-01
      • 2014-05-27
      • 2013-09-04
      • 2016-01-09
      • 1970-01-01
      相关资源
      最近更新 更多