How do I configure my .htaccess file for React App in Subdirectory?

Active3 hr before
Viewed126 times

8 Answers


You can try to add a .htaccess file in your React directory with that source code into it.,How can I make it work properly ? How can I configure my .htaccess file or what fix should I consider ?, Meta Stack Overflow

You can try to add a .htaccess file in your React directory with that source code into it.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdirectory
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
load more v

Where are you storing the .htaccess file?,You’ll need to add a simple .htaccess file, in order to tell the server to fallback to our index.html file. This is the same configuration we would use if the application was on the server root, just with a different absolute path to our index file.,Can you please tell me how I will add .htaccess file, if I am deploying into IIS server.My app is in sub folder.

import { HashRouter, Route } from 'react-router-dom';

// Then in render
  <Route path='/' component={ Home } exact />
  <Route path='/about' component={ About } exact />
load more v

 Pretag team - issue, fix, solve, resolve

And check the apache configuration -> /etc/httpd/conf/httpd.conf,I am starting to think it is somet9ing to do with the LAMP configuation on Lightsail. Any help on this would be much appreciated., Preventing an exodus of other employees while mass firing others? One developer holds a lot of sway?

 Options Indexes FollowSymLinks

 AllowOverride all

 Order allow, deny

 Allow from all

Make build and deploy,Set Basename in Router,Define App Homepage in package.json

 Pretag team - issue, fix, solve, resolve

Step : 3 (add .htaccess file in your project with this configuration)  ,Let me know if I am missing any point so we can add it and can use this blog as one point solution to Deploy React JS in subfolder., Running builds as soon as code is pushed on Git is important and so much relaxing. Creating builds and upload manually every time...


<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteBase /sub-url-name/
 RewriteCond %{REQUEST_FILENAME} -s [OR]
 #Rewrite Conditions 
 RewriteCond %{REQUEST_FILENAME} -l [OR]
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule ^.*$ – [NC,L]
 RewriteRule ^(.*) /sub-url-name/index.html [NC,L]

Now here’s how to finally fix the routing. To tell Apache to redirect requests to index.html where our app lives, we have to modify the .htaccess file. If there is no such file in your app’s folder yet, just create it. ,YEAH! After all that hard work I just deployed my first React app!,After we put that .htaccess file into the same directory as the index.html, Apache will redirect each new request directly to your app.

Then be sure that you put in those 4 lines that will magically make your routing work.

Options - MultiViews
RewriteEngine On
RewriteCond % {
RewriteRule ^ index.html[QSA, L]

Hi, I have used reach-router to create a movie search app. Cannot deploy react app in subfolder using reach-router Hi @Lacika1981 after so many research I found the result, for subfolder you have to create .htaccess file and do this routes to index.html RewriteRule ^ /path/to/subfolder/index.html [L].,Contribute to zacacollier/react-reddit-clone development by creating an If you're using Apache, you need to create a .htaccess file in the public folder that,When you're ready to deploy to production, running npm run build will create an optimized build of your app in the build folder. You can learn more about Create

 Pretag team - issue, fix, solve, resolve

Other "configure-react" queries related to "How do I configure my .htaccess file for React App in Subdirectory?"