【问题标题】:How to add .htaccess redirect to external domain with special characters如何使用特殊字符将 .htaccess 重定向添加到外部域
【发布时间】:2019-11-06 08:02:29
【问题描述】:

就我而言,当我尝试使用特殊字符自动重定向 URL 时,特殊字符会被删除。 在这种情况下如何添加重定向。

来自网址

www.domain1.com/blog/test-blog

到网址

www.domain2.com/test%3a-test1%2a

这是我的重定向代码

RewriteRule ^blog/test-blog?$ https://domain1.com/test%3a-test1%2a [R=301,L]

但是 URL %3 和 %2 中的特殊字符被删除了。

【问题讨论】:

  • 真实地址是www.domain2.com/test:-test1*?

标签: php wordpress .htaccess redirect


【解决方案1】:

您需要在目标中转义%,否则它会被引用为RewriteCond 中捕获组的反向引用。此外,您必须使用 NE 标志以避免在目标 URL 中转义 %

RewriteRule ^blog/test-blog/?$ https://domain2.com/test\%3a-test1\%2a [R=301,L,NE,NC]

【讨论】:

猜你喜欢
  • 2013-06-08
  • 1970-01-01
  • 2016-01-28
  • 2012-12-08
  • 1970-01-01
  • 2018-06-26
  • 1970-01-01
  • 2016-09-23
  • 1970-01-01
相关资源
最近更新 更多