Dhanraj Acharya
Dhanraj Acharya

Reputation: 493

How to redirect all request to index in react or angular using htaccess?

I am creating an application in react using react-router. Earlier I was doing the same with angular but in both cases, if a user bookmarks a URL and loads it directly. It will show 404 error. can we create such rule in htaccess so that the URL doesn't change but the request is passed to index.html.

Upvotes: 9

Views: 8987

Answers (1)

Dhanraj Acharya
Dhanraj Acharya

Reputation: 493

So after much googling and looking through many answers, I found below configuration for htaccess.

it is working as expected and redirects each requests to index.html and from there react router handles everything.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.html [L,QSA]

Upvotes: 23

Related Questions