# Oath Research clone WITHOUT purchase actions (forum / wiki / review site) — Apache / LiteSpeed
#
# Written by postprocess when the site config has "injectModule": false.
# Same as redirect-rules/.htaccess minus the purchase-route 302 rules: custom 404,
# directory index, clean URLs, no directory listing, tooling never served.
#
# On cPanel hosts keep the "# BEGIN cPanel-generated ..." block the host adds;
# never add X-Robots-Tag / noindex headers — the clones must stay indexable.

ErrorDocument 404 /404.html
# ErrorDocument 403 would only change the body, not the status, so the two sources of 403 are
# turned into real 404s further down instead: the tooling block, and a directory with no index.
ErrorDocument 403 /404.html
DirectoryIndex index.html index.htm
Options -Indexes

# Pages, scripts and styles are revalidated on every visit (cheap 304s). Without any
# Cache-Control, browsers keep files "fresh" for hours on their own heuristics, so an
# update would not reach returning visitors. Never use "no-store" here.
<IfModule mod_headers.c>
  <FilesMatch "\.(html?|js|css|json|xml|webmanifest)$">
    Header set Cache-Control "no-cache"
  </FilesMatch>
</IfModule>

RewriteEngine On

# Tooling and notes are never served. 404 rather than 403: a "forbidden" confirms the path is
# there, and a visitor cannot act on either answer.
RewriteRule ^oath-kit(/|$) - [R=404,L]
RewriteRule ^CLAUDE(\.root)?\.md$ - [R=404,L]

# Canonical URLs: a direct .html request 301s to the extension-less URL (added 2026-09-22, client
# request — Google had indexed the clean URLs and they 404'd where this rule did not exist yet).
# %{THE_REQUEST} is the literal request line, so this only fires on what was actually typed/clicked,
# never on the internal rewrite below — no redirect loop. Excludes /404.html (ErrorDocument target)
# and /index.html (directory index); the file-existence check keeps it from firing on fake paths.
RewriteCond %{THE_REQUEST} \s/+(?!(?:404|index)\.html(?:[\s?]))([^\s?]+)\.html[\s?] [NC]
RewriteCond %{DOCUMENT_ROOT}/%1.html -f
RewriteRule ^ /%1 [R=301,L,NE]

# Clean URLs for the static files: /about -> /about.html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
# The pattern excludes a trailing slash. With ^(.+)$ a request for /404/ was rewritten to
# "404/.html" — Apache resolves REQUEST_FILENAME for /404/ to <root>/404, so the -f test found
# the real /404.html and let the rule fire with the slash still in the capture. The result was
# an HTTP 500 on every site in the batch, which is the worst thing to show for a bad URL.
# A directory-style path that does not exist should simply 404.
RewriteRule ^(.*[^/])$ $1.html [L]

# --- gaps in the crawl: do not show a bare 404 (client request, 2026-09-24) -------------
# A missing IMAGE serves the site's placeholder, with a 200 — NOT a redirect. An <img> whose
# request is redirected to an HTML page still renders as a broken image; only real image bytes
# fix it.
# The substitution is RELATIVE on purpose. In a per-directory (.htaccess) context Apache resolves
# it against the directory holding this file, so it finds the right placeholder whether the site
# is served as its own subdomain (docroot = the site folder) or from a sub-path of a shared
# docroot. An absolute /images/placeholder.png only works in the first case.
# Excluding the placeholder itself is what prevents a loop: after the internal rewrite the
# ruleset runs again, and without this it would rewrite the placeholder to itself forever —
# including on a site that has no placeholder at all.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !placeholder\.png$
RewriteRule \.(png|jpe?g|gif|webp|avif|svg)$ images/placeholder.png [L]

# A missing PAGE under a content section goes to that section's index. This variant only had the
# image rule, so on the fourteen sites built without the module a missing page was still a bare
# 404 while the module sites absorbed it — the client's request of 2026-09-24 covers both.
# Every rule is last-resort and self-limiting: the real file, the directory and the .html form all
# have to be absent, and the target index has to exist, so on a site with no such section the rule
# never fires. Anything outside these sections still gets the custom 404 page, deliberately: a
# blanket redirect to the home page hides genuine link errors and reads as a soft 404.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html !-f
RewriteCond %{DOCUMENT_ROOT}/products.html -f
RewriteRule ^products?/ /products [R=302,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html !-f
RewriteCond %{DOCUMENT_ROOT}/reports/index.html -f
RewriteRule ^(?:reports|verify)/ /reports/ [R=302,L,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html !-f
RewriteCond %{DOCUMENT_ROOT}/catalog-product/browse/index.html -f
RewriteRule ^catalog-product/ /catalog-product/browse/ [R=302,L,NE]

# A directory that exists but has no index page gives 403 under Options -Indexes, which reads as
# a permissions fault and confirms the path exists. Some crawls left such directories behind
# (wuxitides /about-us/ holds only subdirectories, and the source answers 404 for it too).
# Answer 404, the same as any other address with nothing at it. Last, so it can only fire
# after every rule above has declined the request.
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/index.html !-f
RewriteCond %{REQUEST_FILENAME}/index.htm !-f
RewriteRule ^ - [R=404,L]

# Fonts / manifest MIME types (in case the host does not know them)
AddType font/woff2 .woff2
AddType font/ttf .ttf
AddType application/manifest+json .webmanifest
