1
votes

Getting 403 Forbidden error while hosting react build app to apache server in ubuntu.

I tried setting up virtual host from /etc/apache2/sites-available/000-default.conf

 <Directory /var/www/html>
       Options Indexes FollowSymLinks
       AllowOverride All
       Require all granted
 </Directory>

Still getting the error. What should I do?

PS: I have the index.html file in /var/www/html/build

1

1 Answers

0
votes

Have you tried adding .htaccess file to the root of your host? If not, add this to .htaccess and then restart apache server.

<IfModule mod_rewrite.c>
    RewriteEngine On
        # If an existing asset or directory is requested go to it as it is
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
        RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
        RewriteRule ^ - [L]
        # If the requested resource doesn't exist, use index.html (in your case /build/index.html)
    RewriteRule ^ /build/index.html
</IfModule>

You have to enable mod_rewrite though.