我想创建一个在Apache服务器上运行的Angular应用。从npm start
本地运行良好,但是从远程Apache部署中丢失了许多文件。我尝试将文件夹src/assets/....
下的字体和i18n文件配置为angular.json
:
"assets": [
"src/favicon.ico",
"src/assets",
"src/web.config"
],
但是当我运行网页时,出现如下错误:
633328.png:1 Failed to load resource: the server responded with a status of 404 (Not Found)
materialdesignicons-webfont14e6.woff2:1 Failed to load resource: the server responded with a status of 404 (Not Found)
fontawesome-webfont3295.woff2:1 Failed to load resource: the server responded with a status of 404 (Not Found)
fontawesome-webfont3295.woff:1 Failed to load resource: the server responded with a status of 404 (Not Found)
materialdesignicons-webfont14e6.woff:1 Failed to load resource: the server responded with a status of 404 (Not Found)
fontawesome-webfont3295.ttf:1 Failed to load resource: the server responded with a status of 404 (Not Found)
materialdesignicons-webfont14e6.ttf:
1加载资源失败:服务器以状态404(未找到)进行响应
因此研究后看来我必须使用以下命令添加映射:https://www.thewebflash.com/set-the-correct-mime-types-for-woff-fonts-in-your-web-server/,但它不起作用。我也尝试添加此配置:https://gist.github.com/vmilev/cf8ef05c2d77fc8aedd6c5831d724a77
但是再次没有运气。您能告诉我如何解决此问题吗?
。htaccess文件
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
<IfModule mod_rewrite.c>
Options Indexes FollowSymLinks
RewriteEngine On
RewriteBase /angular/
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]
</IfModule>
AddType font/woff .woff
AddType font/woff2 .woff2
只需在URL之前在styles.css中添加斜杠。从此更改
angular/assets/fonts/glyphicons-halflings-regular.eot
至此
/angular/assets/fonts/glyphicons-halflings-regular.eot