Configuring Apache to Redirect All Traffic to One Local URL


You want to redirect all requests to your web server to a single page on the server.


Note that redirection to an entirely different server is trivial with RedirectMatch. You can redirect all traffic to to by adding this rule to the Apache config files for

#  Redirecting to another server - WRONG!  Not our goal.
RedirectMatch ^.*$

However, we want to redirect all traffic to one local URL, you might try this

#  Redirecting to this server - WRONG!  Creates infinite redirection.
RedirectMatch ^.*$

This will causes an infinite redirection loop, because every redirection to will trigger the RedirectMatch rule.


Use a negative lookahead in the regular expression. The following configuration will work

#  Redirecting to this server - CORRECT!
RedirectMatch ^(?!/new.html)$

The negative lookahead requires that the requested URL not match /new.html. This prevents the infinite redirection.