Redirecting IP Address to the domain name on Apache and nginx
Normally when you host your domain (website) name on a dedicated IP Address.
The dedicated IP will also server the same content as the domain name.
To resolve this issue, we are going to use the .htaccess in Apache and nginx config
On Apache, use the Below .htaccess code.
RewriteEngine On RewriteCond %{HTTP_HOST} ^192\.168\.192\.1 RewriteRule (.*)$ https://www.earneasy.net/$1 [R=301,L]
change the earneasy.net with your domain name.
On the Above .htaccess eg code, your dedicated IP is : 192.168.192.1 and target redirecting domain name is www.earneasy.net
If you want to redirect any URL from http://ipaddress\subfolder, Just add $ at the end of the IP like below.
RewriteCond %{HTTP_HOST} ^192\.168\.192\.1$ RewriteRule ^(.*)$ "http\:\/\/www\.earneasy\.net\/$1" [R=301,L]
On nginx, use the Below configuration method
On the nginx, we cannot used the same method of .htaccess because of its operating method.
First, find the file & path of the ngnix configuration file.
Normally found in
/etc/nginx/sites-available/domainname.com
use nano or vi editor
nano /etc/nginx/sites-available/domainname.com
and add the below codes in the very bottom of the configuration file. make sure change necessary changes that matches your domain name & IP Address
server { listen 80; server_name 192.168.192.1; return 301 $scheme://earneasy.net$request_uri; }
Just save the file and make sure you restart the ngnix to apply the configurations.
I hope this helps few, if you find any mistakes or corrections, Please do drop us a message.
The above methods are tested personally by me and working 100 Percentage.
Do visit again for more Updates.