我有一个小的Angular 6应用,当使用'ng serve'和localhost:4200时,可以按预期工作。如果我刷新页面或手动输入URL,我会得到预期的结果并加载页面。
但是,当我使用'ng build --base-href = / quickorder /'构建发行版时,应用运行良好,直到刷新或在选项卡中键入url时才找不到URL 404。显示为服务器名称之后的部分。
dist放置在Apache的htdocs中的一个名为quickorder的文件夹中,URL为。 dist的Apache conf文件基本上是标准的,除了更改SRVROOT以反映Apache的位置。
app.modules.ts
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
}
]
感谢您能为我提供的帮助,
标记。
P.S。查看Apache文档(2.4版),如果您可以访问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>
但是,这给了我来自服务器的错误响应; 您无权访问/cgi-bin/dugquickorder.cgi/wh 在此服务器上。
答案 0 :(得分:0)
已解决。在Apache 2.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>
答案 1 :(得分:0)