gpt4 book ai didi

netlify - 使用 netlify 将没有扩展名的 html 页面(又名 'pretty urls' )呈现为 html

转载 作者:行者123 更新时间:2023-12-04 20:28:21 25 4
gpt4 key购买 nike

我正在尝试使用 netlify 来托管静态站点。我正在使用 wget -mk http://hostname/ 构建网站所以我得到了大量的静态文件,并重写了链接。

我想将他们推到 netlify 并让该网站托管。

以 .html 结尾的页面被视为 html 文件并正确显示。

具有“漂亮网址”的页面,例如 /about被视为文本文件,并显示 HTML 标记。

除非我添加重写,否则我无法真正重命名所有这些文件,因为我想保留指向该站点的外部链接。

我尝试设置一个 _headers 文件,但不清楚操作的顺序是什么。这是一个样本 _headers文件:

/*.css
Content-Type: text/css
/*.js
Content-Type: text/javascript
/*.jpg
Content-Type: image/jpg
/*.jpeg
Content-Type: image/jpg
/*.png
Content-Type: image/png
/*.gif
Content-Type: image/gif
/*
Content-Type: text/html

这将所有内容视为 text/html。我可以删除最后一行,但是漂亮的文件会再次被视为文本。

是迭代所有文件并使用完整路径将它们标记为 html 的唯一解决方案,这将使 _headers文件看起来像这样:
/about
Content-Type: text/html
/contact
Content-Type: text/html
...

我查看了 netlify 文档并用谷歌搜索,但找不到任何有用的东西。

最佳答案

为了解决这个问题,我最终编写了一个 shell 脚本来生成 _headers文件。

它看起来像这样:

find `pwd` -type f |grep  -v \\. |sed "s#`pwd`/##" > list
for i in `cat list`; do
echo "/$i" >> _headers;
echo " Content-Type: text/html" >> _headers;
done
rm list

我只是在 _headers 上签到文件和漂亮的 url 处的所有文件都被视为 html。

关于netlify - 使用 netlify 将没有扩展名的 html 页面(又名 'pretty urls' )呈现为 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52731630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com