【问题标题】:Apache Redirect URI RequestsApache 重定向 URI 请求
【发布时间】:2020-02-12 14:47:00
【问题描述】:

我正在尝试将包含特定 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 将是唯一的。你们能不能给我一些指点。我的正则表达式是正确的还是我的重写规则捕获是错误的?

【问题讨论】:

    标签: regex apache mod-rewrite


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      假设您从第一个域的虚拟主机中进行重定向,您可以执行以下操作:

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

      【讨论】:

        猜你喜欢
        • 2012-03-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-04-30
        • 2019-10-12
        • 2011-11-01
        相关资源
        最近更新 更多