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?

已提问 1 年前447 查看次数
1 回答
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.

已回答 1 年前
profile pictureAWS
专家
kentrad
已审核 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则