I am attempting to redirect the IP address of my domain to the domain name and am running into trouble. The IP address does not redirect to the domain name listed in the redirect statement below.The IP Address is 123.123.123.123My .htaccess looks like belowRewriteCond %{HTTP_HOST} ^123\.123\.123\.123$ [NC]RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
redirect the site IP address to the domain name
htaccess
Ordinarily your code should work OK. Although the NC (NOCASE) flag on a numeric value is unnecessary and should be removed.Also note that if you are checking for an exact match (such as a complete IP address) it is usually easier to simply use the = (equals) operator, for example:RewriteCond %{HTTP_HOST} =123.123.123.123This now matches against the plain string 123.123.123.123 (exact match), not a regular expression, so there is no need to escape the dots.Your site also appears to be example.com, not www.example.com so you should change the substitution in the RewriteRule to reflect this, otherwise this will result in a second redirection.However, the main problem in your case seems to be that you are on a shared host - multiple websites hosted on the same IP address (in fact, a rough estimate shows that there are over 500 websites on that IP address). Requesting your server's IP address does not return your website, so attempting to do this kind of redirection is not going to work.