Redirect IP to domain in AWS Lightsail

0

Hi all!

My website Wordpress website https://ririro.com is hosted on an Amazon Lighstail instance with Static IP address 3.125.101.181 attached to it. The problem is that 3.125.101.181 is also accessible for users in the browser various issues mainly on the SEO side.

My research brought me in the direction of making changes to the equivalent of the .htaccess file on Lightsail. However, I wasn't able to specifically find out what changes to make exactly and how to make them.

So, my zoomed out question, what is the best way to make sure that everyone who visits 3.125.101.181 in the browser ends up at https://ririro.com instead?

Thanks in advance for your time and deliberation.

profile picture
Ririro
asked 2 years ago252 views
3 Answers
0

Hi Andy,

Thank you very much for your reply. I've made the changes that you've suggested (https://photos.app.goo.gl/NNsKicxE99qrZi4r7 & https://photos.app.goo.gl/6SjLRq7odw6yTFFj6). The IP address is however still accessible.

Could it be that there's something like an AllowOverride setting somewhere that needs to be changed?

Happy to hear if you have further thoughts.

profile picture
Ririro
answered 2 years ago
  • After making changes, did you restart Apache?

0

Hello,

At a high level overview, you'll want to edit your bitnamic configuration and restart the apache server. Here are changes that should work for your situation.

Make changes in the bitnami.conf and/or bitnami-ssl.conf depending on prior changes made to the instance

sudo nano /opt/bitnami/apache2/conf/bitnami/bitnami.conf
sudo nano /opt/bitnami/apache2/conf/bitnami/bitnami-ssl.conf

#find section like this
<VirtualHost_default_:443>
  DocumentRoot "/opt/bitnami/apache/htdocs"
  SSLEngine On
  #Add the following as a sibling of DocumentRoot, SSLEngine, etc...
  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^ririro.com$
  RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
  RewriteRule ^(.*)$ https://ririro.com$1 [R=permanent,L]
  #end of changes for <VirtualHost_default_:443>

#You may also want to have similar entries for HTTP port 80 if you allow HTTP conns at all
<VirtualHost_default_:80>
  DocumentRoot "/opt/bitnami/apache/htdocs"
  # again, entries are sibling of DocumentRoot
  RewriteEngine On
  RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1)
  RewriteRule ^(.*)$ https://ririro.com$1 [R=permanent,L]
  #end of changes for <VirtualHost_default_:80>

#Restart apache server to pickup your changes
sudo /opt/bitnami/ctlscript.sh restart apache

Please backup any files prior to making changes to give yourself an easy way to back out if changes cause issues.

AWS
MODERATOR
answered 2 years ago
0

You can't actually make your static ip address inaccessible. It is the only way to reach your server from Internet.

Sounds like you want to add a permanent redirect to https://ririro.com when visitors arrive via http://3.125.101.181/.

Note that the visitors who arrive via https://3.125.101.181/ will not even reach your server at all because browsers will refuse to connect to your site, because its SSL server name is ririro.com, not 3.125.101.181.

You'll want to use redirection functionality in your web server. If it's Apache, you'll need to read this: https://httpd.apache.org/docs/2.4/rewrite/

Between reading mod_rewrite Apache documentation and what Andy suggested and searching examples on StackOverflow, you should find the solution.

AWS
MODERATOR
answered 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