Using mod_rewrite to redirect an IP address to a domain name

Posted at October 23, 2015 at 8:30 am by InterServer Staff

To redirect an IP address to a domain name on an apache webserver using .htaccess and mod_rewrite the following can be done.

Lets say you have the domain name on IP address and you do want to redirect the IP address to the domain name if just the IP is accessed (say for SEO purposes). That would be will rewrite to In your .htaccess file add

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

Using the above rule if is accessed a 301 redirect is created to point to


Have we provided you with the highest level of service? Like us on Facebook or write on our wall.

Visit our new community forums at

0.00 avg. rating (0% score) - 0 votes

You can skip to the end and leave a response. Pinging is currently not allowed.

Leave a Reply