首页 > 解决方案 > Angular:返回 URL 错误:在此服务器上找不到请求的 URL

问题描述

我有一个问题,我有一个网站,其中返回上一页会生成此错误:

The requested URL was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the 
request.

当我在我的网站中单击指向另一个外部 URL 的链接时,就会发生这种情况;然后当我点击返回我的页面时

这就是我以角度设置路线的方式:

export const appRoutes: Routes = [

{path: 'users', component: UsersListComponent},
{path: 'products', component: ProductListComponent},
{path: '**', redirectTo: 'users', pathMatch: 'full'}
];

当我构建我的应用程序时,我认为这是我的基本路径index.html

 <title>ProductsWebApp</title>
 <base href="/">

我还想指定该页面确实存在 可能是什么问题?

标签: htmlangularredirect

解决方案


我终于通过将以下内容添加到我的.htaccess文件来解决我的问题

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d

    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^(.*) index.html [NC,L]
</IfModule>

可以在此链接中找到更多信息


推荐阅读