Redirect IP address to domain or URL is required nowadays for production sites due to some security and SEO issues. In this blog, I am going to teach you every single step for Apache and Nginx servers.
People (web owners) ofter think that this issue is solved on the Platform level but it isn’t.
This issue is not caused by AWS, DIgitalOcen, etc clouds, this issue is caused by your server.
So don’t worry this solution work for all platforms.
You are here it means you already checked the issue but to make sure by simply enter your IP in Brower if it loads your website without change the URL it means you have this issue.
Redirecting IP to the domain is necessary nowadays for security and SEO issues.
If you don’t redirect your server’s IP to a domain google and other search engines think both (your IP, and your Domain) are separate websites and this hurts your ranking.
You might use Cloudflare. (If not I highly recommend)
Have you even notice that after setting up Cloudflare your actual webserver’s IP is not available publicly.
And it’s a good practice to make IP private as much as you can.
Follow this step-by-step guide, in order to redirect it to the domain in apache.
If you don’t know how to connect search online you definitely find something great.
In my case “.htaccess” file is located in “/var/www/example.com/public”.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ENTER_YOUR_SERVER_IP
RewriteRule (.*) http://yourdomain.com/$1 [R=301,L]
Don’t forget to replace ENTER_YOUR_SERVER_IP with your actual IP address.
Very Important note: Don’t change anything here just copy and post that code. (As shown in image)
Search how to restart apache in your OS.
This commend will work for, Linux with apache2.
Follow this step-by-step guide, in order to redirect it to the domain in apache.
If you don’t know how to connect search online you definitely find something great.
nginx -V 2>&1 | grep -o '\-\-conf-path=\(.*conf\)' | cut -d '=' -f2
server {
Server_name ENTER_YOUR_SERVER_IP;
return 301 http://yourdomain.com;
}
Don’t forget to replace ENTER_YOUR_SERVER_IP with your actual IP address.
Very Important note: Don’t change anything here just copy and post that code. (As shown in image)
Search how to restart nginx in your OS.
This commend will work for, Ubuntu 18.04 /16.04, CentOS 7/8, and Debian 10 /9 releases.
Let me know on Twitter If you feel this post is not helpful for you.
This website uses cookies.