Server Configurations
Note: The following examples assume you are serving your app from the root folder. If you deploy to a subfolder,you need to adjust the examples below to use the subfolder instead of the root folder (e.g. replacing RewriteBase / with RewriteBase /name-of-your-subfolder/)
#
Apache<IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.html$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.html [L]</IfModule>
Instead of mod_rewrite
, you could also use FallbackResource
#
nginxlocation / { try_files $uri $uri/ /index.html;}
#
Native Node.jsconst http = require('http')const fs = require('fs')const httpPort = 80
http.createServer((req, res) => { fs.readFile('index.html', 'utf-8', (err, content) => { if (err) { console.log('We cannot open "index.html" file.') }
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' })
res.end(content) })}).listen(httpPort, () => { console.log('Server listening on: http://localhost:%s', httpPort)})
#
Express with Node.jsFor Node.js/Express, consider using connect-history-api-fallback middleware.
#
Internet Information Services (IIS)- Install IIS UrlRewrite
- Create a
web.config
file in the root directory of your site with the following:
<?xml version="1.0" encoding="UTF-8"?><configuration> <system.webServer> <rewrite> <rules> <rule name="Handle History Mode and custom 404/500" 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>
#
Caddy v2try_files {path} /
#
Caddy v1rewrite { regexp .* to {path} /}
#
Firebase hostingAdd this to your firebase.json
:
{ "hosting": { "public": "dist", "rewrites": [ { "source": "**", "destination": "/index.html" } ] }}
#
NetlifyCreate _redirects
file in the dist
folder with the following content:
/* /index.html 200
Read more: https://docs.netlify.com/routing/redirects/