angular html5mode in tomcat apache 8.5.4 gives 404 on page refresh

后端 未结 2 411
走了就别回头了
走了就别回头了 2021-01-01 03:47

I m creating war file using gulp-war and deploy it into tomcat apache server 8.5.4 on my system

it first runs on localhost:8080/projectName/

but

相关标签:
2条回答
  • 2021-01-01 04:26

    This is example for The global approach :

    <?xml version='1.0' encoding='utf-8'?>
    <!-- The contents of this file will be loaded for each web application -->
    <Context>
        <!-- REWRITE VALVE -->
        <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
        <!-- // -->
    
        <!-- Speed up context loading -->
        <JarScanner scanClassPath="false" />
        <!-- Default set of monitored resources. If one of these changes, the -->
        <!-- web application will be reloaded.                                 -->
        <WatchedResource>WEB-INF/web.xml</WatchedResource>
    
        <WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
    </Context>
    

    And Just jave added two most popular extensions to your list:

    RewriteCond %{REQUEST_URI} !^.*\.(bmp|css|gif|htc|html?|ico|jpe?g|js|pdf|png|swf|txt|xml|svg|eot|woff|woff2|ttf|map|json)$
    RewriteRule ^(.*)$ /index.html [L]
    

    I like reverse approach (comment by ) but prefer to keep it clean and readable.

    0 讨论(0)
  • 2021-01-01 04:31

    I found the solution with help of this article

    1. add in /opt/tomcat/conf/context.xml

       <!-- REWRITE VALVE -->
       <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
       <!-- // -->  
      
    2. add rewite.config file in specific project WEB-INF folder with below content such as on /opt/tomcat/webapps/projectName/WEB-INF/rewrite.config

      RewriteCond %{REQUEST_URI} !^.*\.(bmp|css|gif|htc|html?|ico|jpe?g|js|pdf|png|swf|txt|xml|svg|eot|woff|woff2|ttf|map)$
      RewriteRule ^(.*)$ /index.html [L]
      

    hope it helps someone

    0 讨论(0)
提交回复
热议问题