tags:

views:

35

answers:

1

Hello,

How do I redirect x.com to y.com, when someone types in x.com or anything x.com

Thanks Jean

+2  A: 

In your apache hosts configuration:

<VirtualHost *:80>
    ServerName y.com *.y.com
    Redirect permanent / http://x.com/
</VirtualHost>
cherouvim
whats the priority?
Jean
Also its immediate if the dns is setup to the same server?
Jean
And its in the .htaccess
Jean
Yes, it's immediate assuming that both x.com and y.com resolve to the same box. This is configuration in your apache hosts file. It will work assuming you don't have another VirtualHost listening to y.com before it.
cherouvim
If you are on limited hosting that only gives you access to configuration via `.htaccess`, you would have to use a nasty mod_rewrite hack conditioned on on the HTTP_HOST name.
bobince
@bobince: that is correct but usually plans such as the one you mention offer cpanel access where from you can setup domain redirects which do the job.
cherouvim
I am on a full root access server, and I cannot seem to find the .htaccess file. logged in as root too
Jean
@Jean: do this in conf/httpd.conf or conf/extra/httpd-vhosts.conf
cherouvim
The main config is not in `.htaccess`, that's only a limited per-directory override. You're looking for what is usually called `httpd.conf`, typically in a directory called `conf` in the same directory that houses `bin/apachectl` et al, which you can find using `which`. (Some distros put this in different places to normal and/or split it up into per-site include files.)
bobince
@bobince Do I need to restart apache once .conf is changed?
Jean
@cherouvim I did a redirect as above, but it does not work. Even restarted httpd
Jean
Yes, a restart is needed to re-read `httpd.conf`. Make sure that no other `<VirtualHost>` (including the main `x.com` site) includes a `ServerName` or `ServerAlias` of `y.com`.
bobince