How Redirect IP Address to Domain Name

When you are using apache or nginx server for WordPress website on cloud hosting. And you want to automatically redirect from ip address to domain name. So follow simple steps using computer.

How to Do

  • First of all open terminal and login there.
  • Now use given command on apache server.
sudo nano /etc/apache2/sites-available/000-default.conf
  • Then make changes like example and SAVE.

<VirtualHost *:80>
ServerName default
Redirect permanent / http://your_domain.com/
</VirtualHost>


  • Now use given command on Nginx server.
sudo nano /etc/nginx/sites-available/default
  • Then make changes like example and SAVE.

server {
listen 80 default_server;
server_name _;
return 301 http://your_domain.com$request_uri;
}

Note

I only test on apache server, And this method working perfectly. Hope this code will work on your apache or Nginx server. Thank for visiting.