0

I was not able to reload pages in my React app (got 404 error), so I had to add the following to my apache conf file:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html [L]

After that change the errors shown in the image appeared:

enter image description here

I have already seen a similar stackoverflow question

But none of the answers related to ReactJS work for me. This has clearly to do with my css files. I am currently storing them in a css folder under the src folder in my project.

Any idea what is going on?

DevB2F
  • 4,674
  • 4
  • 36
  • 60
  • Have you added any external stylesheets? – ravibagul91 Aug 15 '19 at 03:40
  • 1
    Try this .htaccess - `RewriteEngine On RewriteCond %{REQUEST_URI} !^/index.html$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !\.(css|gif|ico|jpg|js|png|swf|txt|svg|woff|ttf|eot)$ RewriteRule . index.html [L]` – ravibagul91 Aug 15 '19 at 03:40
  • these are my css imports: import 'antd/dist/antd.css'; import '../css/myCss.css'; The rewrite code you suggested gives an error: "Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details." – DevB2F Aug 15 '19 at 04:23

1 Answers1

0

I was able to fix the problem by changing the Rewrite code from:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ /index.html [L]

to this:

RewriteEngine On
RewriteCond %{REQUEST_URI} !\.(jpg|png|css|js|map)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ /index.html [L]
DevB2F
  • 4,674
  • 4
  • 36
  • 60