Tomcat 8 URL Rewrite Issues

后端 未结 2 764
Happy的楠姐
Happy的楠姐 2020-12-10 05:56

I have got the tomcat 8 rewrite to work but seems to missing something in rewrite.config that is causing the last condition to not execute. For benefit of others, i have the

2条回答
  •  失恋的感觉
    2020-12-10 06:28

    I seem to have got it fixed. There are couple of things i found and sharing it for others. The below thing worked finally for me. Below are the contents in rewrite.config. It should be placed in webapps//WEB-INF/ directory.

    RewriteCond %{REQUEST_URI} .*\.(css|js|html|png|jpg|jpeg|gif|txt|ttf|json|woff|ico)$ [OR]
    RewriteCond %{REQUEST_URI} ^(/api/).*$ [OR]
    RewriteRule ^(.*)$ - [L]
    
    RewriteRule ^(.*)$ /index.html 
    

    There are a couple of things that were needed. The way i ensure my app is the default app is by adding below snippet in HOST configuration in server.xml. Please note that if you are using this approach to make your app the default app the valve adding should be done in the Context block in server.xml and it works and putting the same in your application/META-INF/context.xml does not seem to do the trick. It surely loads the configuration but rewrite does not happen. The PreResources thing kept in the application/META-INF/context.xml seems to work fine.

    server.xml snippet

    
    
            
                
              
            ....
    
    

    HTH, Thanks

提交回复
热议问题