无法从部署在Apache服务器上的angular应用程序加载文件 [英] Cannot load files from angular app deployed on Apache server
问题描述
我想创建一个在Apache服务器上运行的Angular应用.从npm start
本地运行良好,但是从远程Apache部署缺少许多文件.我试图将文件夹src/assets/....
下的字体和i18n文件配置为angular.json
:
I want to create an Angular app which is run on Apache server. Locally from npm start
it's running well but from remote Apache deployment many files are missing. I tried to configure fonts and i18n files under the folder src/assets/....
into angular.json
:
"assets": [
"src/favicon.ico",
"src/assets",
"src/web.config"
],
但是当我运行网页时,出现类似以下错误:
But when I run the web page I get errors like:
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(未找到)
1 Failed to load resource: the server responded with a status of 404 (Not Found)
因此,经过研究后,我似乎不得不使用以下方法添加映射: https://www.thewebflash.com/set-the-correct-mime-types-for-woff-fonts-in-your-web-server/但它不起作用.我还尝试添加此配置: https://gist.github.com/vmilev/cf8ef05c2d77fc8aedd6c5831d724a77
So after research looks like I have to add mapping using this: https://www.thewebflash.com/set-the-correct-mime-types-for-woff-fonts-in-your-web-server/ but it's not working. I also tried to add this configuration: https://gist.github.com/vmilev/cf8ef05c2d77fc8aedd6c5831d724a77
但是再次没有运气.您能告诉我如何解决此问题吗?
But again no luck. Can you give me some idea how this can be fixed?
.htaccess文件
.htaccess file
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中添加斜杠.更改
just add slash in styles.css before urls. Change from this
angular/assets/fonts/glyphicons-halflings-regular.eot
对此
/angular/assets/fonts/glyphicons-halflings-regular.eot
这篇关于无法从部署在Apache服务器上的angular应用程序加载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!