Configuring Apache to Redirect All Traffic to One Local URL
- May
- 20
- Posted by TKH Specialist
- Posted in apache, linux
GOAL
You want to redirect all requests to your web server to a single page on the server.
PROBLEM
Note that redirection to an entirely different server is trivial with RedirectMatch. You can redirect all traffic to http://my-server.org to http://other-server.org by adding this rule to the Apache config files for http://my-server.org
# Redirecting to another server - WRONG! Not our goal. RedirectMatch ^.*$ http://other-server.org/
However, we want to redirect all traffic to one local URL, you might try this
# Redirecting to this server - WRONG! Creates infinite redirection. RedirectMatch ^.*$ http://my-server.org/new.html
This will causes an infinite redirection loop, because every redirection to http://my-server.org/new.html will trigger the RedirectMatch rule.
SOLUTION
Use a negative lookahead in the regular expression. The following configuration will work
# Redirecting to this server - CORRECT! RedirectMatch ^(?!/new.html)$ http://my-server.org/new.html
The negative lookahead requires that the requested URL not match /new.html. This prevents the infinite redirection.
Recent Comments
- Stefan on Flush This!
- Timestamping your Bash History | Matt's Entropy on Remember when you issued that command…?
- Matt Smith on Remember when you issued that command…?
- Ruan on Putting ‘lsof’ to use
- Dylan F. Marquis on External Mapping of LDAP attributes in CAS