How do I redirect a static IP address to a website URL in Lightsail?

1 minute read
0

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:

  1. Use SSH to connect to Lightsail.

  2. Access the root user:

    # sudo su-
  3. 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
  4. Open the configuration file:

    # vi /opt/bitnami/apache/conf/vhosts/wordpress-vhost.conf
  5. 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.

  6. 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.

  7. Restart Apache:

    # /opt/bitnami/ctlscript.sh restart apache
AWS OFFICIAL
AWS OFFICIALUpdated 3 months ago