Tomcat 8 URL Rewrite

邮差的信 提交于 2019-11-29 03:50:29

I have found the solution, problem was in wrong/faulty rewrite.config file. Correct should be:

RewriteCond %{REQUEST_URI} ^/(css|img|js|partials|rest|favicon).*$
RewriteRule ^.*$ - [L]

RewriteRule ^.*$ /index.html [L,QSA]

On the first line are enumerated URIs which should not be rewritten. Everything else will be rewritten to index.html.

Is this deployed as a java web app (WAR)? You could implement this in your web.xml:

<servlet>
   <servlet-name>index</servlet-name>
   <jsp-file>/index.html</jsp-file>
</servlet>

<servlet-mapping>
   <servlet-name>index</servlet-name>
   <url-pattern>/</url-pattern>
   <url-pattern>/about</url-pattern>
   .. as many as you need ..
<servlet-mapping>

I couldn't get this to work with the REQUEST_URI, and I didn't like having to whitelist specific files anyway, so I solved it in a slightly different manner.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!