skip to Main Content

I am trying to upload my application to Plesk and it is working fine except when i try to render non .HTML page component for example it through error 404 page not found I understand this related to the server but I don`t know how to fix it.
I have uploaded the same application on Vercel and it is working fine on all pages and components.

<Route exact path="/" render={() => {window.location.href="Home.html"}} />
<Route path="/quiz" component={App} />
<Route path="/questions" render={() => {window.location.href="questions.html"}} />
<Route path="/profile" render={() => {window.location.href="profile.html"}} />
<Route path="/about" render={() => {window.location.href="about.html"}} />

As u can see most of my routes are to .HTML pages and they are all working when i visit domain/quiz i get 404 page not found.

I would appreciate if there is a fix for that.

And i have already tried to create the .htaccess as recommended in many previous solutions but it did not solve the problem.

2

Answers


  1. Chosen as BEST ANSWER

    The solution suggested by this https://stackoverflow.com/a/60342849/7345217 worked

    Create a .htaccess file in the Public folder of your React App.

    Put these lines in the file

    <IfModule mod_rewrite.c>
       Options -MultiViews
       RewriteEngine On
       RewriteCond %{REQUEST_FILENAME} !-f
       RewriteRule ^ index.html [QSA,L]
    </IfModule>
    

    Save and (npm react or yarn build) and it should work


  2. In my case i create a .htaccess file in the Public folder of your React App.
    Put these lines in the file

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

    and create a _redirects file in the Public folder of your React App.

    Put this lines in the file

    /*    /index.html   200
    

    also create web.config in plesk hosting folder where build is uploaded and wrote

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.webServer>
        <httpErrors errorMode="Custom" existingResponse="Replace">
            <remove statusCode="404" subStatusCode="-1" />
            <error statusCode="404" path="/" responseMode="ExecuteURL" />
        </httpErrors>
      </system.webServer>
    </configuration>
    

    and it works..!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search