/ 的 Apache 2.2 重写规则不重定向

Apache 2.2 rewrite rule for / is not redirecting

我在 apache 中有配置文件应该重定向/请求到不同的 url。

但是当我点击 /

时我得到了 404

请求将发送到后端服务器,但不会重定向。

配置文件是

#This is not getting invoked. Returning 404.
#Request is redirected to app2.adobecqms.net with out appending page1/page2.html
RedirectMatch ^/$ https://app1.abc.com/page1/page2.html

RewriteCond %{REQUEST_URI} ^/folder1/folder2
RewriteCond %{REQUEST_URI} !^/(.*)\.(json|html)
RewriteRule ^/(.*)$ http://app2.adobecqms.net/.html [P]

RewriteCond %{REQUEST_URI} ^/analytics.txt
RewriteRule ^/(.*)$ http://app2.adobecqms.net/page1/page2/page3/ [P]

#I also tried with below. But no luck
#This is returning 502
#RewriteRule ^/$ https://app1.abc.com/page1/page2.html [P]

有什么想法吗?

#This is not getting invoked. Returning 404.
#Request is redirected to app2.adobecqms.net with out appending page1/page2.html
RedirectMatch ^/$ https://app1.abc.com/page1/page2.html

因为您正在使用 mod_alias RedirectMatch 指令,该指令在 另一个 mod_rewrite (RewriteRule) 之后处理指令与配置文件中指令的顺序无关。

And/or 你有 ProxyPass 转发其他请求的指令? mod_rewrite 需要覆盖它。

这里也需要使用mod_rewrite RewriteRule 以避免冲突。例如:

RewriteRule ^/$ https://app1.abc.com/page1/page2.html [R=302,L]

并且此指令应该 现有指令之前。 (虽然在这种情况下不应该有冲突。)需要 L 标志。

P 标志通过 mod_proxy 发送请求 - 这不是“重定向”。

您发布的 RedirectMatch 指令将默认为 302(临时)重定向,正如我在此处使用的那样。但是,如果这是永久性的,则更改为 301,但前提是您确认它按预期工作(以避免缓存问题)。