tomcat apache 8.5.4中的角度html5mode在页面刷新上给出404 [英] angular html5mode in tomcat apache 8.5.4 gives 404 on page refresh

查看:192
本文介绍了tomcat apache 8.5.4中的角度html5mode在页面刷新上给出404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用gulp-war创建war文件,并将其部署到系统上的tomcat apache服务器8.5.4中

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

它首先在localhost:8080/projectName/

,但是每当刷新页面时,它就会显示 404错误.如何解决此问题?

but whenever I refresh the page it gives 404 error . How to fix this issue?

如果我从配置文件中删除了$locationProvider.html5Mode(true);,并且比创建war文件好了,那么它就可以正常工作了

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

一切正常,但URl随附/#/

than everything works fine but URl comes with /#/

我尝试添加.htaccess文件,但没有区别

I tried with adding .htaccess file but no difference

有人解决吗?

推荐答案

我在

  • 添加/opt/tomcat/conf/context.xml

     <!-- REWRITE VALVE -->
     <Valve className="org.apache.catalina.valves.rewrite.RewriteValve" />
     <!-- // -->  
    

  • 在特定项目 WEB-INF 文件夹中添加 rewite.config 文件,该文件具有以下内容,例如/opt/tomcat/webapps/projectName/WEB-INF/rewrite.config

  • 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]
    

  • 希望它对某人有帮助

    这篇关于tomcat apache 8.5.4中的角度html5mode在页面刷新上给出404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆