Forum Moderators: phranque

Message Too Old, No Replies

Redirect an entire domain to a new one using httpd.conf

         

mazza82

3:30 pm on Nov 11, 2011 (gmt 0)

10+ Year Member



hi!

my problem is the following:

i want to redirect permanently a domain (let's say www.example.com) to a new one (let's say www.newone.com).

i've seen many examples using the .httaccess file but not using httpd.conf.

i would like to redirect all that domain (let's say www.example.com/*) and the non www. URL as well.

any suggestion?

many thanks in advance ;)

g1smd

8:00 pm on Nov 11, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Using a RewriteRule, the code is essentially the same if redirecting all URLs.

If only certain URLs need redirecting, the main difference is that the RegEx pattern for the version in the httpd.conf file will need to match the leading slash of the path.

mazza82

4:33 pm on Nov 12, 2011 (gmt 0)

10+ Year Member



ok, i've arrived to this piece of code to add to the httpd.conf:


<VirtualHost ?>
ServerName example.com
ServerAlias example.com
ServerAlias www.example.com
Redirect permanent / http//www.newone.com/
</VirtualHost>


i still need some aclarations:

what do i have to put in the virtualhost line instead of "?" ?

and what's the difference between servername and serveralias?

thanks!

wheel

5:44 pm on Nov 12, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't just drop that code randomly into your httpd.conf. You should already have a <VirtualHost>...</VirtualHost> container for your domain inside your httpd.conf file or perhaps in another file located in your vhosts subdirectory. Put that code inside those VirtualHost tags, don't make new ones. Which answers your first question as to the '?' - it's whatever is there already. Note that these may not be in httpd.conf, in my server they are in a vhosts directory in another file.

Name is the name. Alias is a different name for the same domain. I don't think your example makes any sense, since they're the same domain. I use it like this:
ServerName www.example.com
ServerAlias www.example2.com
ServerAlias www.example3.com

So that example1.com, example2.com and example3.com all show the same website. I don't believe that the ServerAlias adds anything to your code, but again, I could be wrong.

mazza82

8:23 pm on Nov 12, 2011 (gmt 0)

10+ Year Member



So maybe this is the correct code:

<VirtualHost ?>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / http//www.newone.com/
</VirtualHost>


i just need the virtualhost and that's all..

can anyone confirm this? i will ask for the virtual host to my sysadmin..

wheel

1:47 am on Nov 13, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is an example from my server:
<VirtualHost *:80>
ServerName www.domain-a.com
ServerAlias domain-a.com
redirect 301 / [destination-domain.com...]
</VirtualHost>

And I know that works. Sorry, I'm not expert enough to tell you if yours works or not.