Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 666
Dhanraj Acharya Avatar asked Jul 17 '18 11:07

Dhanraj Acharya


1 Answers

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]
like image 139
Dhanraj Acharya Avatar answered Nov 15 '22 06:11

Dhanraj Acharya