Cpanel WHM, set IP > domain redirect for all sites on server

apache-2.2redirect

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.

Best Answer

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