Make ip address redirect to real name with Apache

Solution 1:

HD answered gave a good rewrite rule, but you should put a condition before that. Make sure that there is only one virtual host running on 10.10.10.1 and have your definition look like the following:

<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>

This way, you only need one virtual host for that IP address instead of what you were trying to do above. NOTE: If you're going to have more than one virtual host on this server, you need to put the rest on different IP(s)

Solution 2:

I try the same configuration and it works fine. Are you sure there is no other definition that conflicts with your virtual hosts? What is the error in the apache logs?

This rule also works:

RewriteRule ^(.*)$ http://example.com/$1 [R=301,NC]