How to setup apache server for React route?

前端 未结 9 1095
无人共我
无人共我 2020-12-08 10:04

I have my react app running great on my local dev server but it did not work when I dump my production ready files straight into Apache\'s htdocs directory:

Here is

9条回答
  •  甜味超标
    2020-12-08 10:45

    What worked for me, echoing many of the answers and comments here:

    1. sudo a2enmod rewrite
    2. Open up /etc/apache2/apache2.conf
    3. Paste in this:
    ">
        RewriteEngine on
        # Don't rewrite files or directories
        RewriteCond %{REQUEST_FILENAME} -f [OR]
        RewriteCond %{REQUEST_FILENAME} -d
        RewriteRule ^ - [L]
        # Rewrite everything else to index.html to allow html5 state links
        RewriteRule ^ index.html [L]
    
    
    1. sudo service apache2 restart

    Pasting into the site-specific conf file did not work as earlier answers suggested.

提交回复
热议问题