skip to Main Content

I’m having trouble getting my create react app build to properly route to my components on my server.

I have a .htaccess file

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]

so that it always routes to my index.html

the url to my site is .com/project and my homepage option in my package.json file is homepage: '/project'

I have ran out of things to do.

Because of my htaccess it’s always routing to my index.html but the router is always loading the 404 component. What am I missing.

2

Answers


  1. Chosen as BEST ANSWER

    This occured because the base routing was wrong so it was constitently routing to the 404 page.

    Setting the <Router basename="/<Directory>"> and adding the homepage option to my package.json file fixed this problem.


  2. For me worked with this .htaccess:

    RewriteEngine On
    RewriteBase /project
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.html?$1 [L,QSA]
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search