I have domain.com and domain.org as aliases pointing to the same vhost. How can I use .htaccess to redirect all domain.com requests to domain.org?
+2
A:
You could use mod_rewrite to do this.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^example\.org$
RewriteRule ^ http://example.org%{REQUEST_URI} [L,R=301]
This rule redirects every request that’s not addressed to example.org
to the very same.
Gumbo
2009-04-29 17:33:38
A:
Or you could use Redirect permanent like
Redirect permanent / http://domain.org/
which will force the browser to refresh the domain on client side. (While the rewrite would happen server-side.) So the solution depends on what you want.
mattanja
2009-04-29 17:55:49
I don’t think this would work. Both host names share the same virtual host so example.org would also be redirected.
Gumbo
2009-04-29 18:09:25
Ah ok. So if you can't create two different vhosts the rewrite would be the way to go.
mattanja
2009-04-29 18:12:03
The `R` flag used in my example forces an external HTTP redirect with the status code 301.
Gumbo
2009-04-29 18:13:45