1

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

How can I enable mod_rewrite?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.