Apache config for React Router

0
(0)

This works fine on url’s like example.com/component (react router fires upcomponent), but fails on routes like example.com/component/othercomponent. The react router can navigate fine to these hypothetical url’s once the app is loaded, but Apache is confused.

.htaccess

<IfModule mod_rewrite.c>

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

</IfModule>

On gist.github

Second version of .htaccess

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

Apache and LiteSpeed server do not need to restart.

Similar Posts:

2,319

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Scroll to Top