Redirect a Domain (Apache)

4 posts / 0 new
Last post
#1 Tue, 03/15/2011 - 16:40
rauldinho

Redirect a Domain (Apache)

hi, I host a domain called www.example.com and I created another one like www.example.net, and they both point to my web server. I need to make that when people go to the www.example.com domain the server changes the URL to www.example.net. Can anyone help on how to achieve this? Thanks in advanced and sorry for my english.

Tue, 03/15/2011 - 17:40
andreychek

Howdy,

You may want to look at System Settings -> Server Templates -> Default -> Apache Website, and review the "Create alias websites by" option. You can change that to "Creating Redirect virtual host" or "Creating permanent Redirect virtual host".

That would only effect newly created aliases -- so after you set that up, you'd need to delete and then re-add the alias.

-Eric

Wed, 03/16/2011 - 06:06
Locutus

Additionally, if you don't wish to change the default behavior for alias creation, you can set up the alias with the "Add ServerAlias to parent domain" option, and then use Services -> Configure Website -> Edit Directives to add a block like so:

RewriteEngine on
RewriteCond %{HTTP_HOST} =www.example.com
RewriteRule ^(.*) http://www.example.net$1 [R]

This will use Apache's mod_rewrite to perform the redirection. Or you add the line that Virtualmin adds when using the option Eric suggested:

RedirectPermanent / http://www.example.net/

The latter can also be done through Webmin's Apache module, section Aliases and redirects.

Wed, 03/16/2011 - 08:20
rauldinho

Thank you! Both solutions worked well.

Topic locked