Redirecting IP Address to the domain name on Apache and nginx

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

apacheOn Apache, use the Below .htaccess code.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^192\.168\.192\.1
RewriteRule (.*)$$1 [R=301,L]

change the with your domain name.

On the Above .htaccess eg code, your dedicated IP is : and target redirecting domain name is

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]

nginxOn 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

use nano or vi editor

nano /etc/nginx/sites-available/

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;
return 301 $scheme://$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.


This site uses Akismet to reduce spam. Learn how your comment data is processed.