React App – htaccess File Not Redirecting Routes

amazon-lightsaillamp

I am currenlty hosting my React App on an Amazon Lightsail LAMP instance. I have two versions of an htaccess file. One works for me when I host my React App on GoDaddy cPanel webhosting. I found the other online while trying to get the routing working.

This is the one that works on Godaddy:

RewriteEngine On 
RewriteBase /
  RewriteRule ^index\.html$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

This is the one I found online:

Options +FollowSymLinks -MultiViews
  RewriteEngine On
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteRule ^ index.html [QSA,L]

I am starting to think it is somet9ing to do with the LAMP configuation on Lightsail. Any help on this would be much appreciated.

EDIT 1:

As requested by Aiden:

I am in currently trying to migrate from GoDaddy cPanel Web Hosting to an Amazon Lightsail instance running LAMP. My web app has been created using React. The .htaccess file is supposed to redirect the client to index.html which is where the new content will be loaded by the JS. My .htaccess file works with GoDaddy but not on the Lightsail instance. I am assuming it is a configuration issue in LAMP. I have tried setting what was suggested by Aiden to no avail. My .htaccess file is in the htdocs folder.

Best Answer

To get better understanding can we get an idea of where you are and where you want to be (Redirect) either non-existing pages to index.php or any other.

Try the same in .htaccess

RewriteEngine On

RewriteBase /

RewriteRule ^index.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

You can have better control over the processing versus creating different handler files and having apache capture the data and give it to the appropriate handler or variable ID

And check the apache configuration -> /etc/httpd/conf/httpd.conf

 Options Indexes FollowSymLinks

 AllowOverride all

 Order allow,deny

 Allow from all

Related Topic