Question

A record redirects to ip instead of domain

I have 2 web applications which are on different hosts. The main one (example.com) is on another hosting with domain connected to it, the second one (sub.example.com) is a wordpress website on DigitalOcean. For this, in the dns manager I created an A record which is pointing to ip of the DigitalOcean Droplet. After that, I setted the wordpress application with the desired subdomain and added SSL certificate for the subdomain in droplet.

The connection is working fine, when I’m accessing sub.example.com, it is redirecting to the wordpress website, but if users for the first time type sub.example.com, they are being redirected to https://ip_adress and gets a “ERR_CERT_COMMON_NAME_INVALID”

I tried to add a redirect from ip to subdomain in apache config, but without any result…

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^18\.182\.216\.244$1
RewriteRule ^(.*)$ https://sub.example.com/$1 [L,R=301]
</IfModule>

What can I do to solve this issue ?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there,

Once you’ve pointed your domain name to your server IP address, you would also need to define your new WordPress site and home URLs so that they match your new domain name. One way to do that would be to add the following to your wp-config.php file:

define( 'WP_HOME', 'https://yoursiteurl.com' );
define( 'WP_SITEURL', 'https://yoursiteurl.com' );

Make sure to also install an SSL certificate so that you could have HTTPS enabled:

https://www.digitalocean.com/community/tutorials/how-to-secure-apache-with-let-s-encrypt-on-ubuntu-18-04

Best,

Bobby