Arham Awan
Arham Awan

Reputation: 634

Setting .htaccess file for my react project

I have deployed two react builds on cpanel, basically one is admin panel and second website like this: Cpanel

admin folder consist of build of admin panel working on /admin route. client folder consist of build of website working on / route.

My .htaccess Code:

<IfModule mod_rewrite.c>
RewriteEngine on 

# first check if request is in /client/
RewriteCond %{DOCUMENT_ROOT}/client%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/client%{REQUEST_URI} -d
RewriteRule ^(.*)$ /client/$1 [L]


# then check if request is in /admin/
RewriteCond %{DOCUMENT_ROOT}/admin%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/admin%{REQUEST_URI} -d
RewriteRule ^(.*)$ /admin/$1 [L]

</IfModule>

After long searching I found this code as solution for my app as two react apps are deployed in cpanel. The problem is that whenever I refresh on any route page gives 404 error although routes work perfect. Please Help.

Upvotes: 1

Views: 8159

Answers (1)

Ali Faris
Ali Faris

Reputation: 18610

I'm using these rules for my react applications, in my cases I have one react application not two

<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>

Upvotes: 7

Related Questions