I have config file in apache that should redirect / request to different url.
But i am getting 404 when i hit /
Request is going to backend server but it is not redirecting.
Config file is
#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/$1.html [P]
RewriteCond %{REQUEST_URI} ^/analytics.txt
RewriteRule ^/(.*)$ http://app2.adobecqms.net/page1/page2/page3/$1 [P]
#I also tried with below. But no luck
#This is returning 502
#RewriteRule ^/$ https://app1.abc.com/page1/page2.html [P]
Any idea?
Because you are using a mod_alias
RedirectMatchdirective, which is processed after the other mod_rewrite (RewriteRule) directives despite the order of directives in the config file.And/or you have
ProxyPassdirectives that forward other requests? mod_rewrite is required to override this.You need to use mod_rewrite
RewriteRulehere also in order to avoid the conflict. For example:And this directive should be before the existing directives. (Although there shouldn't be a conflict in this case.) The
Lflag is required.The
Pflag sends the request through mod_proxy - this isn't a "redirect".The
RedirectMatchdirective you posted would default to a 302 (temporary) redirect, as I used here. However, if this is intended to be permanent then change to a 301, but only once you have confirmed that it works as intended (to avoid caching issues).