URL rewriting - Ember Routes on Apache Tomcat?

I have deployed my ember app in Apache Tomcat version 9.

The index page works fine localhost:8080/myemberapp/ but when i try to access localhost:8080/myemberapp/login it returns 404 error .

I also Read about URL rewriting and added the following code snippet to .htaccess file

#html5 pushstate (history) support:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.html [L]

And added the following to tomcat conf/context.xml file

<Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />

But still I cannot access any other ember routes after deploying in Apache Tomcat.

Can anybody solve this so that, each routes in the ember app can be mapped to a custom URL.

Hi @Ruban_Thilak, welcome! This is more of a Tomcat config question so I’m not sure how much help we’ll be able to give you. Some quick googling makes it sounds like htaccess doesn’t necessarily work right with Tomcat and maybe you should use WEB_INF? That’s just a shot in the dark on my part though.

FWIW you can just serve your Ember app with Apache or any other static file server if that makes things any easier.

I’ve had a couple of these problems on deploy. The term in single page apps like this is “fallback url.” The technology changes per release because it’s a relatively new “problem.” This is a pretty standard way of solving it from what I have found though I find it a little bit ham fisted. It’s nice to actually return 404 when needed, but it is what it is. Ymmv

1 Like