Ionic 4 - Build for browser

I want to run the app on a web server ( static files hosting ) and having a problem.

Assume the app runs with domain and inside it routes to different pages let’s say, the issue if the user refreshes the browser then it would fail to load because the web server would try to open the folder ‘products’ in the root directory.

Command to build:
ionic cordova build browser

@ionic/angular": "^4.0.0-rc.0


ionic cordova platform add browser
ionic cordova build browser --prod

Already added ‘browser’ platform, and building in production for sure is not the cause.

add following code in your .htaccess file

RewriteEngine on
# Don’t rewrite files or directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
# Rewrite everything else to index.html to allow HTML5 state links
RewriteRule ^ index.html [L]


Thank you after adding these codes to .htaccess . I can open any path . and there is no more problem after refresh the page

Hi where to add and use .htaccess file

please explain

where to add .htaccess file ?

Consult the documentation for whatever httpd (webserver) you are using.

1 Like