Static IP of wordpress site is not redirecting to domain name

0

I am new to AWS, but not new to wordpress. I have created a wordpress website in AWS Lightsail. I noticed my static IP is not redirecting to my domain name. My domain name is - cinemachaser.com and the static IP is - 3.109.134.63.

The question may seem silly to aws expert, but when I was typing the IP (3.109.134.63), I was hoping it would redirect to my domain name cinemachaser.com. But it was not. However the wordpress was accessible. Then I typed cinemachaser.com and again my site was accessible. Means my wordpress website was accesible with my Static IP as well as my domain name.

I logged into WP-admin of site (3.109.134.63/wp-admin) and found that in settings, default url was the ip itself 3.109.134.63.

I checked cinemachaser.com/wp-admin and in this the default url was my domain name, not the IP.

This should not happen, i guess. The static IP should redirect to domain name, I guess.

I then, found a solution and edited wp-config file and deleted the following code - define('WP_SITEURL', 'http://' . $_SERVER['HTTP_HOST'] . '/'); define('WP_HOME', 'http://' . $_SERVER['HTTP_HOST'] . '/'); and replaced it with define('WP_SITEURL', 'http://DOMAIN/'); define('WP_HOME', 'http://DOMAIN/');

Now, the default site url in the wp-admin is changed back to domain name.

But the concern is that, the frontend of the website is also accessible via static ip. 3.109.134.63 is still loading the website However, 3.109.134.63/wp-admin is redirecting it to cinemachaser.com/wp-admin

Is it not possible such that when I type the static IP, it redirects completely to domain name?

asked a year ago388 views
1 Answer
1

There isn't a way to do this via DNS, but you can do it via an .htaccess configuration:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^3.109.134.63$ [OR]
RewriteRule (.*)$ https://cinemachaser.com/$1 [R=301,L]

It also appears that there are some Wordpress plugins like Redirection that would accomplish this, though your mileage may vary on this solution.

answered a year ago
profile pictureAWS
EXPERT
kentrad
reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions