[Howto] redirect URL with Apache httpd without mod_rewrite

posted in: computer | 0

Apache httpd supports PCRE (=perl compatible regular extensions). Be careful of the syntax, because the regex must be enclosed by “/” and you have to use “=~” to enable pcre.

 

This example redirects “<any>.olddomain.<any>” to “http://www.newdomain.com

<If "%{HTTP_HOST} =~ /.*olddomain.*/">
   Redirect permanent "/" "http://www.newdomain.com/"
</If>

 

This example redirects “<any>.olddomain.<any>” or “www.example.com” to “http://www.newdomain.com

<If "%{HTTP_HOST} =~ /(.*olddomain.*)|(www.example.com)/">
   Redirect permanent "/" "http://www.newdomain.com/"
</If>