Recipe 5.17 Redirecting All Requests to a Single Host


You want all requests made of your system to be redirected to a specific host.


Put this in your httpd.conf:

RewriteCond "%{HTTP_HOST}"   "!^$"       [NC,OR] RewriteCond "%{SERVER_NAME}" "!^$"       [NC] RewriteRule "(.*)"           "$1" [R]


Any request handled by your server within the scope of the directives in the Solution (which aren't directed to the host) is redirected there.

The two different RewriteCond directives are used to catch all requests made by some host other than, regardless of the redirection method.

The NC (No Case) flag makes the regular expression case-insensitive. That is, it makes it match regardless of whether letters are upper- or lowercase.

The OR flag is a logical "or," allowing the two conditions to be strung together so that either one being true is a sufficient condition for the rule to be applied.

Finally, the R flag causes an actual Redirect to be issued, so that the browser will make another request for the generated URL.

See Also


Apache Cookbook
Apache Cookbook: Solutions and Examples for Apache Administrators
ISBN: 0596529945
EAN: 2147483647
Year: 2006
Pages: 215

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: