Apache 2.x and mod_rewrite
    Jeremy Turner 
    jeremy at linuxwebguy.com
       
    Sat Nov 27 18:48:51 CST 2004
    
    
  
On Sat, Nov 27, 2004 at 03:03:35PM -0600, Dustin Decker wrote:
> I've been trolling documentation at apache.org, but their examples are
> flying over my head.  For the purposes of example, let's say I have
> purchased two domains - foo.com and foo.org.  What I want to occur (without
> leaning on an http-equiv redirect in the browser), is to have anyone who
> visits www.foo.com <http://www.foo.com/>  automagically redirected to
> www.foo.org <http://www.foo.org/> .
Slashdot does something similar.  Rather than www.slashdot.org, it
redirects you to slashdot.org (try it sometime).  Apache2 config would
look something like this in your case:
<VirtualHost *>
	ServerName www.foo.org
	ServerAlias www.foo.com,foo.com,foo.org
	DocumentRoot /home/www/foo.org/
	# Turn rewrite engine on
	RewriteEngine On
	# Set logging on
	RewriteLog /var/log/apache2/rewrite.log
	# Match foo.com
	RewriteCond %{HTTP_HOST}   !^www\.foo\.com [NC]
	# Match anything else
	RewriteCond %{HTTP_HOST}   !^$
	# www.foo.com/test/1 ==> www.foo.org/test/1
	RewriteRule ^/(.*)         http://www.foo.org/$1 [L,R]
</VirtualHost>
I've used it on one of my sites.  Basically any paths on www.foo.com are
redirected to www.foo.org.
It's probably overkill for your needs, but it might be what you're
looking for.
Jeremy
    
    
More information about the Kclug
mailing list