我希望你做得很好。我刚刚使用 CLI 为 godaddy 部署了一个我最近一直在工作的非营利组织网站(可在此处找到:www.leonesistersunited.com)。部署后,一切都和预期的一样好。但是,在任何页面上,如果您刷新浏览器,都会收到 404 错误。关于可能导致这种情况的任何想法?是我的问题还是 GoDaddy 的问题?我在 Windows 层 (IIS) 上托管。
谢谢。
我希望你做得很好。我刚刚使用 CLI 为 godaddy 部署了一个我最近一直在工作的非营利组织网站(可在此处找到:www.leonesistersunited.com)。部署后,一切都和预期的一样好。但是,在任何页面上,如果您刷新浏览器,都会收到 404 错误。关于可能导致这种情况的任何想法?是我的问题还是 GoDaddy 的问题?我在 Windows 层 (IIS) 上托管。
谢谢。
对于 GoDaddy 网络托管有两种不同的解决方案
在 Angular index.html 中编写 base-href
<base href="/nameOfTheappFolder/"> or
部署 ng build --prod --base-href "/nameOfTheAppFolder/"
在你角度 6 app.module 调用这个提供程序
providers: [{ provide: APP_BASE_HREF, useValue: '/nameForTheAppFolder/'}]
对于 Linux 主机,您可以像这样执行 .htacces 文件,在其中替换应用程序目录文件夹名称
<IfModule mod_rewrite.c>
Options Indexes FollowSymLinks
RewriteEngine On
RewriteBase /myappdirectory/
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /myappdirectory/index.html [L]
</IfModule>
对于 Windows 托管,您需要执行 web.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="./index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
您需要使用重写模块部分部署 web.config。如果godaddy服务器安装了它(他们应该)那么这就是所需要的
添加带有 URL 重写规则的 web.config 文件 对此 Web 应用程序的所有不是针对文件或文件夹的请求都应定向到应用程序的根目录。对于默认网站下的应用程序或虚拟目录,应将 URL 设置为别名(例如“/MyApp/”)。对于服务器根目录的网站,URL 应设置为“/”。
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Angular Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="/MyApp/" />
<!--<action type="Rewrite" url="/" />-->
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>