I have setup my lightsail instance with a static IP and my React app in the htdocs folder. I am trying to prevent anyone from accessing it via the public url. (Making it so that before you can access it, you need to be SSH'd into the lightsail instance.) Currently, my htaccess file currently only redirects the homepage and not any of the other pages. My htaccess file is as follows.

RewriteEngine On
RewriteBase /

    RewriteCond %{HTTP_HOST} ^$
    RewriteRule ^/?$ [R=301,L]

    RewriteCond %{HTTP_HOST} ^$
    RewriteRule ^/?$ [R=301,L]

EDIT 1: As suggested below:

I have added the suggested code to my virtual host in 000-default.conf. I have also installed what was needed and made sure everything was activated. I am able to restart Apache without any arrors. However, when I navigate to the public IP Address, it does not redirect to localhost. My code is as follows:

<VirtualHost *:*>
    ProxyPreserveHost On
    ProxyPass /
    ProxyPassReverse /
    ServerName localhost

1 Answer 1


You're probably looking for enabling reverse proxy in Apache. You can read more about it here:


Instead of using the rewrite module, try using the proxy module and add the following lines:

ProxyPass / ProxyPassReverse /

Hope this helps!

  • Could you please take a look at my edit above? I am having some trouble with the Proxy.
    – Chris
    Commented Aug 15, 2019 at 6:52
  • Please try using <VirtualHost *:80> and then ServerName domain.com
    – johnsing
    Commented Aug 15, 2019 at 6:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .