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
질문됨 2년 전257회 조회
3개 답변
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
답변함 2년 전
  • 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
중재자
답변함 2년 전
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
중재자
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠