htaccess重定向所有以xxx查询字符串开头的路由

时间:2019-06-25 08:17:32

标签: php wordpress .htaccess woocommerce

我在 $http({ method: "post", url: '/Login/Login', data: { "login": LogIn} }) 中使用以下代码将.htaccess(wordpress)的子域重定向到Domain1

Domain2

一切正常。

但是我的产品下载链接在RewriteEngine On RewriteCond %{HTTP_HOST} ^learn.Domain1\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.learn.Domain1\.com$ RewriteRule ^(.*)$ "https\:\/\/\Domain2\.com\/$1" [R=301,L] 中将该电子邮件链接到用户以供下载:

woocommerce

我使用此learn.Domain1.com/?download_file=xxxxxxxxxxxxxxxxxx 重定向,但下载网址除外:

cond

但这不起作用!

我该如何解决?

1 个答案:

答案 0 :(得分:2)

您在这里有2个问题:

  • 正则表达式中的Project Interpreter表示“开头为”,而您的URI并非由查询参数开头
  • the docs中所述,^不包含请求参数,请尝试使用REQUEST_URI
QUERY_STRING

注意:由于RewriteCond %{QUERY_STRING} !^download_file=(.*) ,仅当参数^是第一个参数时,此方法才有效;如果不是,则可以使用:

download_file