How to redirect wrong URL path

Latest update of ionic made the url so clean by removing excess keywords. By using code below able to remove hashbang # inside the url path.

IonicModule.forRoot(MyApp, {
    locationStrategy: 'path'

I had set the @IonicPage

  segment: 'home'

After deployed to my server, I access the page like below: -> able to access homepage -> 404 not found

My question is, are there any methods to redirect user to different pages if user direct access a non-existing URL path? Like what router can do:

 {path: '404', component: NotFoundComponent},
 {path: '**', redirectTo: '/404'}

Thank you. Any recommendation and suggestions are welcome.

One way would to just catch these 404s on your webserver and redirect to the correct URL. (Only works for URLs without # as the stuff behind # is not actually transmitted to the server)

Thanks for the reply.
Yes webserver config could do the url redirection. But due to some reason I couldn’t add in the config. After digging much research and advices, I have found another solution. Since I’m deploying my app as war file, so adding code below to web.xml could simple do the trick. This could be one suggestions to others who need to do the same thing as me. Thanks.


Could you elaborate that a bit? What server software are you using?