1. Home
  2. Helpful Tips
  3. How to Redirect IP Address to Your Domain Name

How to Redirect IP Address to Your Domain Name

Here’s how I remap IP address traffic to my domain name with Apache:

<VirtualHost *:80>
    #block direct IP address traffic
    ServerName localhost
    #remap traffic to IP address to my domain name
    RewriteEngine On
    RewriteRule ^ https://mydomain.com        
</VirtualHost>

<VirtualHost *:80>
    ServerName mydomain.com
    ServerAlias www.mydomain.com
DocumentRoot "/var/www/mydomain"
<Directory "/var/www/mydomain/">
      Options FollowSymLinks
      AllowOverride All
</Directory>

You can also block direct IP address traffic to your website using your .htaccess file:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^12\.34\.56\.789$
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]
Updated on April 17, 2017

Was this article helpful?

Related Articles

Leave a Comment