Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Having html pages without an extension (aka 'pretty urls') render as html using netlify

I'm trying to use netlify to host a static site. I'm building the site using wget -mk http://hostname/ so I get a large number of static files, with links rewritten.

I'd like to push them to netlify and have that host the site.

Pages that end in .html are treated as html files and are displayed correctly.

Pages that have 'pretty urls' like /about are treated like text files, and the HTML markup is displayed.

I can't really rename all these files unless I add rewrites because there are external links to the site that I want to preserve.

I tried setting up a _headers file but it wasn't clear what the order of operations was. Here's a sample _headers file:

/*.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

This treats everything as text/html. I could remove the last line, but then the files that are pretty are treated as text again.

Is the only solution to iterate all the files and mark them as html using the full path, which would make the _headers file look something like this:

/about
  Content-Type: text/html
/contact
  Content-Type: text/html
...

I looked in the netlify documentation and googled and wasn't able to find anything useful.

like image 246
mooreds Avatar asked Oct 10 '18 02:10

mooreds


1 Answers

To solve the problem I ended up writing a shell script to generate the _headers file.

It looks like this:

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

I just check in the _headers file and all the files at pretty urls are treated as html.

like image 135
mooreds Avatar answered Oct 05 '22 02:10

mooreds