Direct URL Access

For direct URL access to Flutter web app pages, you need to modify the server configuration where the flutter web app is hosted

Nginx

In case of Nginx you need to modify the site specific config file placed in sites-available folder. Add below code (location) to ensure proper URL redirection.

server {
   
     listen 443      ssl http2;
    ...............................
    ..............................
    
    location / {
        try_files $uri $uri/ /index.html;
        }  
          
    }

Apache

For Apache, add the following rewrite rule to your Apache configuration file (usually located at /etc/apache2/sites-available/your-site-config-file)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.html [L]

Firebase Hosting

In Firebase Hosting, you can configure URL rewriting by adding the following rewrite rule to your firebase.json file:

{
  "hosting": {
    "rewrites": [
      {
        "source": "**",
        "destination": "/index.html"
      }
    ]
  }
}

Last updated