Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a WHM/cpanel server with about 200 sites on it. Most sites have a dedicated ip (about 100 of them) The other sites are on a shared ip.

The dedicated sites can be accseed by the ip address eg, http://123.123.123.123.

Is there a way to set up a mass redirect so that every site on a dedicated ip gets it's ip address redirected to the domain. E.g just make the default behavior of the web server to redirect an IP to the corresponding domain.

I know you can do this for each site via .htaccess or apache config file, but I want to avoid having to modify 100 sites, and have to do it again every time i create a new account.

share|improve this question
    
In all my cPanel servers, the dedicate IP automatically redirects to the corrisponding domain without any particular config. Which WHM version are you using? –  Mr Shunz Mar 6 '11 at 11:20

1 Answer 1

Someone can correct me when I am wrong here, but I do not believe an easy solution/button exists for such a thing.

As you mentioned, .htaccess is a solution. Another solution would be to edit the virutalhost entires in your Apache log as such:

<VirtualHost 10.0.0.1:80>
    ServerName servername.com
    .....

    RewriteCond %{SERVER_NAME} 10.10.10.1
    RewriteRule /(.*) http://servername.com/$1 [R=301,L]
</VirtualHost>

Of course you can automate this using bash, perl or any other scripting language you would like. For new accounts that contain a dedicated IP address, you can always use cPanel/WHM API for this sort of thing: post/pre ww account creation

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.