: Redirect the site IP address to the domain name 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
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.123
My .htaccess looks like below
RewriteCond %{HTTP_HOST} ^123.123.123.123$ [NC]
RewriteRule ^(.*)$ www.example.com/ [L,R=301]
More posts by @Ravi8258870
1 Comments
Sorted by latest first Latest Oldest Best
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.123
This 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 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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.