简体   繁体   English

Apache httpd 刷新

[英]Apache httpd refresh

I am working on an angular project with routing and it works fine in local.我正在开发一个带有路由的角度项目,它在本地运行良好。 When I deploy the same in Apache httpd, on browser refresh from any page it gives the error 'The requested URL was not found on this server.'当我在 Apache httpd 中部署相同的内容时,在从任何页面刷新浏览器时,它会给出错误“在此服务器上找不到请求的 URL”。

The comments of MikeOne and Chad K are right, that is one way of solving this issue. MikeOne 和 Chad K 的评论是对的,这是解决此问题的一种方法。

Firstly, when you build an app for production ng build --prod sometimes you need to change the base href in the index.html if the app is not in the root of your webserver, I think this is not your problem but you could check it anyway.首先,当您为生产ng build --prod构建应用程序时,如果应用程序不在您的网络服务器的根目录中,有时您需要更改index.htmlbase href ,我认为这不是您的问题,但您可以检查反正它。

After that, let's say your routing is going to ' http://yourserver/page1/ ' when the app is reloaded from that URL the webserver will try to find a directory named page1 which does not exist.之后,假设您的路由将转到“ http://yourserver/page1/ ”,当从该 URL 重新加载应用程序时,网络服务器将尝试查找名为page1的目录,但该目录不存在。 The proposed solutions on the comments would work, using apache mod rewrite.建议的评论解决方案将起作用,使用 apache mod 重写。 An that solution would only work if you have access to the configuration files of that server or if it uses .htaccess files, which sometimes is not the case.只有当您有权访问该服务器的配置文件或者它使用.htaccess文件时,该解决方案才有效,有时情况并非如此。 However, if you don't mind having the URLs a little bit different there is another much simpler solution.但是,如果您不介意 URL 稍有不同,还有另一种更简单的解决方案。

in the import of the RouterModule where there is something like:RouterModuleimport中,有如下内容:

RouterModule.forRoot( routes )

You can add the useHash this way:您可以通过以下方式添加useHash

RouterModule.forRoot( routes, { useHash: true } )

then rebuild your project with the production flag and the URLs now will be like:然后使用生产标志重建您的项目,现在的 URL 将如下所示:

http://yourserver/#/page1/

this way, thanks to the hash, the app will work without any problems and the only thing needed is setting the useHash on the RouterModule and rebuilding your app.这样,多亏了散列,应用程序将毫无问题地工作,唯一需要的是在useHash上设置 useHash 并重建您的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在nginx或apache httpd中构建angular 4应用程序? - How to build angular 4 apps in nginx or apache httpd? 部署到Apache 2 HTTPD Server时Angular 7路由不起作用 - Angular 7 Routes not working when deployed to Apache 2 HTTPD Server 在角度4,nginx服务器和apache的路由刷新404 - 404 on route refresh in angular 4, nginx server and apache Angular 2 路由无法使用 Apache 刷新页面 - Angular 2 routing not working on page refresh with Apache Angular 13 app deployed on apache server throwing 404 Error on refresh - Angular 13 app deployed on apache server throwing 404 Error on refresh 服务器上的角度刷新返回404错误-使用.htacess的Apache服务器 - Angular refresh on server returns 404 error - apache server using .htacess 刷新 浏览器 Angular 应用程序不工作。 将应用程序部署到 apache tomcat 时出现 404 错误 - Refresh The browser Angular app is not working. giving 404 error when I deployed the app in to apache tomcat 角查询参数,如 httpd_query_params - Angular query params like httpd_query_params Angular 8:如何在没有刷新令牌的情况下刷新令牌 - Angular 8: How to refresh a token without a refresh token 如何在ionic 2中刷新页面或刷新ngOnInit() - How to refresh a page or refresh ngOnInit() in ionic 2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM