Howdy All,
I have a quick question on Apache 2.x (2.0.51 to be precise) and mod_rewrite.
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/ .
Can anyone share with me a recipe for this that I can chew on. (Or even better, considering how lazy I am, just throw up and live with!)
Thanks,
Dustin Decker
Hi,
Mod_rewrite might be overkill for what you are trying to do. If you have mod_alias you can just use a virtual host and redirect to the new site.
<VirtualHost 192.168.1.1> ServerName www.foo.com ServerAlias foo.com Redirect / http://www.foo.org/ </VirtualHost>
More info here:
http://httpd.apache.org/docs-2.0/mod/mod_alias.html#redirect
Regards, Tim Canon
On Nov 27, 2004, at 3:03 PM, Dustin Decker wrote:
Howdy All,
I have a quick question on Apache 2.x (2.0.51 to be precise) and mod_rewrite.
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 automagically redirected to www.foo.org.
Can anyone share with me a recipe for this that I can chew on. (Or even better, considering how lazy I am, just throw up and live with!)
Thanks,
Dustin Decker _______________________________________________ Kclug mailing list [email protected] http://kclug.org/mailman/listinfo/kclug
-----Original Message----- From: Timothy A. Canon [mailto:[email protected]] Sent: Saturday, November 27, 2004 3:56 PM To: [email protected] Cc: [email protected] Subject: Re: Apache 2.x and mod_rewrite
Hi,
Mod_rewrite might be overkill for what you are trying to do. If you have mod_alias you can just use a virtual host and redirect to the new site.
<VirtualHost 192.168.1.1> ServerName www.foo.com ServerAlias foo.com Redirect / http://www.foo.org/
</VirtualHost>
More info here:
http://httpd.apache.org/docs-2.0/mod/mod_alias.html#redirect
Regards, Tim Canon
Tim and Jeremy both - thanks so much for this information. It's precisely what I was looking for.
Dustin
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