I want to redirect a static IP address to a website URL in Amazon Lightsail.
Resolution
To redirect a static IP address to a website URL in Lightsail, complete the following steps:
-
Use SSH to connect to Lightsail.
-
Access the root user:
# sudo su-
-
Back up the virtual host file:
# cp -prf /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf.Orig
-
Open the configuration file:
# vi /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf
-
Add the redirect rule before # END WordPress:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example-domain$
RewriteCond %{HTTP_HOST} !^(localhost|127.0.0.1) RewriteRule ^(.*)$ http://example-domain [R=permanent,L]
Note: Replace example-domain with the client domain name.
-
Save the file and check the Apache syntax:
# apachectl -t
If the output includes Syntax OK, then proceed to step 7. If you receive a different output, then make sure that the redirect rule matches the previous step.
-
Restart Apache:
# /opt/bitnami/ctlscript.sh restart apache