How to redirect an IP address to a domain using mod_rewrite?

Sometimes you need to redirect an ip address to a domain for SEO purposes or for many other reasons, for example an account with a dedicated ip to the domain name. This can be performed easily using mod_rewrite.

For example if your ip is, accessing to will redirect you to

Simply add the following lines in the .htaccess file in your public_html directory changing the domain and the ip number with your information:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^10\.10\.10\.10
RewriteRule (.*)$1 [R=301,L]

Using this rule if is accessed then a 301 redirect is created to point to

Was this answer helpful? 4 Users Found This Useful (1066 Votes)