部署到Apache时出现Angular 6路由问题(找不到URL 404)
我有一个小的Angular 6应用程序,在使用“ng serve”和localhost:4200时可以正常工作。如果我刷新一个页面或手动键入一个URL,我会得到预期的结果并加载页面 但是,当我使用“ng build--base href=/quickorder/”构建发行版时,应用程序运行良好,直到我刷新或在选项卡中键入url时,我才获得url not found 404,url显示为服务器名称后面的部分 dist放在Apache的htdocs中名为quickorder的文件夹中,URL为。 dist的apacheconf文件基本上是标准的,除了修改SRVROOT以反映Apache的位置之外 app.modules.ts部署到Apache时出现Angular 6路由问题(找不到URL 404),angular,routing,Angular,Routing,我有一个小的Angular 6应用程序,在使用“ng serve”和localhost:4200时可以正常工作。如果我刷新一个页面或手动键入一个URL,我会得到预期的结果并加载页面 但是,当我使用“ng build--base href=/quickorder/”构建发行版时,应用程序运行良好,直到我刷新或在选项卡中键入url时,我才获得url not found 404,url显示为服务器名称后面的部分 dist放在Apache的htdocs中名为quickorder的文件夹中,URL为。 d
const appRoutes:Routes = [
{
path: '',
component: LoginComponent
},
{
path: 'order-input/:ref/:name',
canActivate: [AuthguardGuard],
component: OrderInputComponent
},
{
path: 'order-input',
canActivate: [AuthguardGuard],
component: OrderInputComponent
},
{
path: 'trad-verify',
canActivate: [AuthguardGuard],
component: TradVerifyComponent
},
{
path: '**',
component: LoginComponent
}
]
谢谢你能为我提供的一切帮助
马克
另外,查看2.4版的Apache文档,如果您可以访问httpd.conf,并且所有.htaccess命令都可以进入httpd.conf,他们建议不要使用.htaccess
<Directory />
RewriteEngine On
RewriteBase /quickorder
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html
Options FollowSymLinks
AllowOverride All
#AllowOverride none
#Require all denied
</Directory>
重新启动发动机
重写基本/快速订单
#如果请求了现有资产或目录,请按原样转到该资产或目录
RewriteCond%{DOCUMENT_ROOT}%{REQUEST_URI}-f[或]
重写cond%{DOCUMENT\u ROOT}%{REQUEST\u URI}-d
重写规则^-[L]
#如果请求的资源不存在,请使用index.html
重写规则^/index.html
选项如下符号链接
允许超越所有
#不允许超限
#要求全部拒绝
然而,这给了我一个来自服务器的错误响应;
您没有访问/cgi-bin/dugquickorder.cgi/wh的权限
在此服务器上。已解决。在Apache2.4中,不需要.htaccess文件(如果您有权访问httpd.conf)。更改可以进入“目录”中
#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
AllowOverride none
Require all denied
</Directory>
<Directory C:\Apache\Apache24\htdocs\quickorder\>
RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ \index.html
AllowOverride All
</Directory>
#
#拒绝访问服务器的整个文件系统。你必须
#明确允许访问其他目录中的web内容目录
#下面的街区。
#
不允许超限
要求全部拒绝
重新启动发动机
#如果请求了现有资产或目录,请按原样转到该资产或目录
RewriteCond%{DOCUMENT_ROOT}%{REQUEST_URI}-f[或]
重写cond%{DOCUMENT\u ROOT}%{REQUEST\u URI}-d
重写规则^-[L]
#如果请求的资源不存在,请使用index.html
重写规则^\index.html
允许超越所有
请参阅以下链接:
这有助于解决问题。我没有使用任何
.htaccess
文件,但是已经覆盖了httpd.conf
您的。htaccess
应该将每个传入请求重定向到index.html
。您好,谢谢。我在Windows上,在Apache文件夹中看不到.htaccess文件。你能提供一个如何做到这一点的例子吗?很抱歉,我不能,我知道答案,但不知道如何应用它们(mostyle,因为我从未使用过Apache)。快速的谷歌搜索会向你解释:没问题。我现在在谷歌上搜索…(我给了你一个网站)