0

I have 3 domain names for one site. e.g example1.com, example2.com, example3.com. I want to redirect example2.com and example3.com to example1.com. I know this has to do with redirecting, but where do I put the redirect rules? in apache, or .htaccess. Any pointers? Currently I have this set up as 3 different virtual hosts pointing to the same folder. Thank you.

berto77
  • 111

2 Answers2

1

You can do this with either .htaccess or by add Rewrite rules in the VirtualHost config directly. The apache docs here would tell you not to use .htaccess if you can edit the server config. If you do this in .htaccess when you don't need to, apache has to first check if this file exists for every page hit.

For the redirect itself, you could use something like Redirect 301 / http://example1.com if you want http://example2.com/foo/bar/baz to redirect to http://example1.com/ ; if you want it to actually redirect to http://exmple1.com/foo/bar/baz (retaining the rest of the url after the hostname), you can instead use RedirectMatch 301 ^(.*)$ http://example1.com$1 The docs for Redirect and RedirectMatch are here

stew
  • 9,588
0

You can do this with DNS. In your external DNS records point example2.com and example3.com to the external IP of example1.com.

HostBits
  • 11,945