dinesh balan
dinesh balan

Reputation: 348

Flutter web 404 Not Found

Flutter Web after deploy in server 404 will appear I know flutter is single page application so we configure the .htaccess file

RewriteEngine on
RewriteCond %{REQUEST_FILENAME}% !-d
RewriteCond %{REQUEST_FILENAME}% !-f
RewriteRule . /index.html [L]

but I use one static html file render in app so this method is not working ​and also I tried 404.html. No use please help me

Upvotes: 1

Views: 1616

Answers (3)

raw
raw

Reputation: 149

Referring to MrWhite's answer and johannesmilke's video

Creating the file under './myApp/web/.htaccess'

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /index.html [L]

seems to do the trick. And it seems it will also be included in the build by doing so.

Upvotes: 1

FaezehYas
FaezehYas

Reputation: 21

I published my flutter web release on a windows server IIS and I got error on reload. For the 404 error on the reload of my flutter page, I add a web.config file in the root of my publish beside index.html and I added this code inside.

 <?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
      <rewrite>
        <rules> 
          <rule name="Main Rule" stopProcessing="true">
            <match url=".*" />
            <conditions logicalGrouping="MatchAll">
              <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
              <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Rewrite" url="/" />
          </rule>
        </rules>
      </rewrite>
    </system.webServer>
</configuration>

Upvotes: 2

MrWhite
MrWhite

Reputation: 45829

RewriteCond %{REQUEST_FILENAME}% !-d
RewriteCond %{REQUEST_FILENAME}% !-f

You have an erroneous literal % at the end of the TestString argument, so these negated conditions will always be successful, including when the request is rewritten to /index.html.

These conditions should be written:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

But note that for requests to the document root to be correctly rewritten you need to ensure that the DirectoryIndex is correctly set. For example:

DirectoryIndex index.html

Upvotes: 3

Related Questions