How-to
Website
Web app
Serve a site with Apache
This recipe serves a WebFluent build with Apache, configured by an .htaccess file that ships with the build. You need an Apache host with mod_rewrite and mod_headers, and a build/ folder from wf build (Install wf on a build machine). Put this in public/.htaccess:
Options -MultiViews
RewriteEngine On
# A single-page build:
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteRule ^ /index.html [L]
ErrorDocument 404 /404.html
Header always set X-Content-Type-Options "nosniff"
Header always set X-Frame-Options "DENY"
Header always set Referrer-Policy "strict-origin-when-cross-origin"
How it works
Then upload build/ to the site's document root.
- The build copies
public/.htaccessto the root ofbuild/, so it lands in the document root with the site. - For a single-page build, uncomment the two rewrite lines: a path that is no file is answered with
index.html, where the router draws the page. ErrorDocument 404 /404.htmlserves the page whosepathis*.- The
Headerlines send security headers the build writes tobuild/_headers(Set cache and security headers).
Check it
curl -I a page and check for X-Content-Type-Options, X-Frame-Options and Referrer-Policy. With the .gz rules, curl -sI -H "Accept-Encoding: gzip" https://example.com/app.js answers Content-Encoding: gzip and Content-Type: text/javascript. Open a path that does not exist and check that you get the site's 404.html. Then go through Check a deploy.
Variations
Compress the text files one of two ways:
- Turn on
mod_deflate, which compresses on the way out. This is the simplest, and covers every text file. - Serve the
.gzfiles the build wrote, so Apache compresses nothing itself.Options MultiViewsdoes not do it: content negotiation only runs when the file asked for does not exist, andapp.jsdoes. Add these lines afterRewriteEngine On, before the single-page lines, as Apache's ownmod_deflatedocumentation does it:
# Sent with the right type, and not compressed a second time RewriteRule "\.css\.gz$" "-" [T=text/css,E=no-gzip:1] RewriteRule "\.js\.gz$" "-" [T=text/javascript,E=no-gzip:1]
<FilesMatch "\.(css|js)\.gz$"> Header append Content-Encoding gzip Header append Vary Accept-Encoding </FilesMatch> ```
This covers the scripts and stylesheets, the largest files. Pages are asked for by their folder (`/contact/`), which the rule cannot see as a file, so leave `mod_deflate` on for HTML.