Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular html5mode in tomcat apache 8.5.4 gives 404 on page refresh

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 whenever I refresh the page it gives 404 error . How to fix this issue?

if I remove $locationProvider.html5Mode(true); from config file and than creat war file than it working fine

than everything works fine but URl comes with /#/

I tried with adding .htaccess file but no difference

anyone has the solution ?

like image 367
diEcho Avatar asked Dec 08 '22 21:12

diEcho


1 Answers

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

like image 54
diEcho Avatar answered Dec 30 '22 07:12

diEcho