IP address to the main website URL

We thought we would share this information for people using Apache Web Servers who require to redirect the IP address of a website hosting to the main website URL. If you have a dedicated IP address it is well worth checking this.

If the web hosting server IP address is not forwarding to the website’s domain name then you may find that search engines could index your website content using IP address rather than the domain name itself.

If this did occur it would mean that there is a potential of duplicate content so we recommend you check this by putting your webservers IP address in your browser.

If it does not redirect to the main website URL then you can fix this using a htaccess 301 redirect on an Apache server.


Options +FollowSymLinks
RewriteEngine on
#
# Redirect non www to your www.yourdomain.com
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com$
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

-or-

Options +FollowSymLinks
RewriteEngine on
#
# Redirect non www and also the server IP Address to your www.yourdomain.com
RewriteCond %{HTTP_HOST} ^yourdomain\.com [OR]
RewriteCond %{HTTP_HOST} ^123\.456\.789\.101
RewriteRule (.*) http://www.yourdomain.com/$1 [R=301,L]

Be careful to add your IP address without damaging the code as it requires the “\” between the “.”