Regex Apache重定向URI请求

Regex Apache重定向URI请求,regex,apache,mod-rewrite,Regex,Apache,Mod Rewrite,我试图将包含特定URI的http请求重定向到具有完全不同URI的不同域。重定向顶级域是可行的,但我似乎无法重定向URI规则 从本质上讲,它应采取以下行动: 如果url请求为: www.example.com/unique-URI 它需要重定向到: https://example2.com/anotheruniqueURI 目前我有: RewriteEngine On #This redirect works successfully RewriteCond %{HTTP_HOS

我试图将包含特定URI的http请求重定向到具有完全不同URI的不同域。重定向顶级域是可行的,但我似乎无法重定向URI规则

从本质上讲,它应采取以下行动:

如果url请求为:

www.example.com/unique-URI
它需要重定向到:

https://example2.com/anotheruniqueURI
目前我有:

  RewriteEngine On

  #This redirect works successfully
  RewriteCond %{HTTP_HOST} ^www\.example\.com$
  RewriteRule ^(.*)$ http://example2.com/something [R=301,L]

  #This attempt to redirect requests with the specific URI does not work.
  RewriteCond %{HTTP_HOST} ^www\.example\.com
  RewriteCond %{REQUEST_URI} ^/cars-application$ [NC]
  RewriteRule ^/(.*)$ https://example2.com/anotherURI/ [R=301,NC,L]

我在我的
RewriteRule
中尝试了许多不同的组合,比如像我在上面的RewriteCond中那样显式地声明URI,但这不起作用。在这里使用$1将不适用,因为我正在重定向到一个完全不同的域和URI。我期望的URI是唯一的。你们能给我一些建议吗。我的正则表达式是正确的还是重写规则捕获错误

假设您是从第一个域的virtualhost中重定向,您可以只执行以下操作:

Redirect permanent /unique-URI http://www.domain2.com/newlocation 

由于规则模式中的前导斜杠,规则无法工作。删除斜杠以修复它

RewriteRule ^(.*)$ https://example2.com/anotherURI/ [R=301,NC,L]