php - htaccess 重定向所有路由以 xxx 查询字符串开头
问题描述
我使用以下代码将(wordpress).htaccess
的子域重定向到: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
重定向,但下载 URL 除外:
RewriteCond %{REQUEST_URI} !^/?download_file=
但这不起作用!
我该如何解决?
解决方案
你在这里有两个问题:
- 正
^
则表达式中的 表示“开始于”,并且您的 URI 不是由查询参数开始的 - 如文档中所述,
REQUEST_URI
不包括请求参数,请尝试QUERY_STRING
:
RewriteCond %{QUERY_STRING} !^download_file=(.*)
注意:由于^
,这仅在参数download_file
是第一个时才有效,如果不是这种情况,您可以使用:
RewriteCond %{QUERY_STRING} !(?:^|&)download_file=(.*)
推荐阅读
- ibm-cloud - Watson IoT:仪表板图无法从 cloudant 检索信息
- c++ - 具有多个枚举的 C++ 运行时类型切换
- amazon-web-services - 从 API Gateway HTTP 代理访问 VPC 中的 AWS Elasticsearch
- sql - 通过对单列中的相同值进行分组来选择多个结果?
- angular - Angular 8 Plotly - 图表作为类吸气剂冻结页面
- php - MySQL插入数据后的外来字符
- wordpress - 对多个子目录使用主网站的数据库
- javascript - 通过包装使容器的元素填充容器的高度
- javascript - 如何在reactjs中的带下划线的单词上显示下拉菜单
- python - 将字符串列转换为列表列