【发布时间】: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