【问题标题】:htaccess redirect value and discard keyhtaccess 重定向值和丢弃键
【发布时间】:2019-05-01 10:22:19
【问题描述】:

我想做一个 Apache .htaccess 重定向如下:

https://domain1.com/app/index.php?ref=1234

到

https://domain2.com/ref/1234

如何编写这条规则?看来我想丢弃ref=参数,然后动态使用该值(本例中为1234)。

URL 数以千计,因此需要动态获取值 (1234)。

我已阅读 HTACCESS Redirect ID Value 和 https://perishablepress.com/redirect-query-string-htaccess/ 但似乎无法正常工作。

我已经在.htaccess for domain1.com 中尝试过这个:

RewriteRule ^index.php?ref=/([0-9]+)/ https://domain2.com/ref/$1 [L,NC,QSA]

【问题讨论】:

    标签: apache .htaccess redirect


    【解决方案1】:

    RewriteRule 模式最初将与主机名和端口之后的 URL 部分匹配,在查询字符串之前。如果您希望匹配主机名、端口或查询字符串,请使用带有%{HTTP_HOST}、%{SERVER_PORT} 或%{QUERY_STRING} 变量的RewriteCond。

    这应该可行:

    RewriteCond %{QUERY_STRING} ref=([0-9]+)
    RewriteRule ^index.php https://domain2.com/ref/%1 [R,L,NC,QSD]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-01
      • 2016-08-13
      • 2023-03-12
      • 2013-12-30
      相关资源
      最近更新 更多