fix(seo): permanent apex redirect, real 404s, and gallery links that resolve

Three routing fixes, all in nginx.conf so they live in version control.

Apex to www is now a 301. Traefik was answering 307 because Coolify generates
`redirectregex.permanent=false` and hardcodes it, so pinning the label would be
overwritten on the next deploy. Moving the redirect into the container means the
app's `redirect` setting in Coolify must be `both`, otherwise Traefik still
redirects the apex before nginx ever sees it. A temporary redirect consolidates
nothing, and every canonical on the site pointed through it.

Unknown paths now return 404 instead of 200 with the SPA shell. The app routes
entirely through the hash (#/pricing, #/auth/callback), which never reaches the
server, so nothing deep-links to a path and the fallback was load-bearing for
nothing. Answering 200 with byte-identical markup for every made-up path made
the site look like a single page duplicated infinitely. The 404 body is a
branded page generated by the same renderer, marked noindex and kept out of both
the sitemap and llms.txt.

/gallery and /video/* now 301 to api.openshorts.app, which is where those
server-rendered pages actually live. The README has linked them on the apex since
they were written, and the apex quietly served the landing page instead.

Verified against the production nginx config in a container: 15 real routes 200,
6 made-up paths 404, both gallery paths 301 to the API host, apex 301s to www
preserving path and query. Coolify's health check for this app is disabled and
would target /, which still returns 200.
This commit is contained in:
juancarlos.cavero 2026-07-27 11:48:33 +02:00
parent ce67cdcdf5
commit 985761a340
3 changed files with 78 additions and 4 deletions

View file

@ -1,5 +1,24 @@
# Apex to www, permanently.
#
# Traefik was doing this with `redirectregex.permanent=false`, which answers 307.
# A temporary redirect does not consolidate ranking signals, so every canonical
# on the site named a URL that only ever redirects. Coolify regenerates its
# Traefik labels on every deploy and hardcodes permanent=false, so pinning it
# there would be overwritten; the redirect lives here instead, in version
# control. This requires the app's `redirect` setting in Coolify to be `both`,
# so Traefik routes the apex through to this container rather than redirecting
# it first.
server {
listen 80;
server_name openshorts.app;
return 301 https://www.openshorts.app$request_uri;
}
server {
# Explicitly the default server: the block above claims a specific
# server_name, and without this marker nginx would fall back to whichever
# block is declared first.
listen 80 default_server;
server_name _;
root /usr/share/nginx/html;
index index.html;
@ -11,7 +30,17 @@ server {
try_files $uri =404;
}
# SPA: serve index.html for any route (hash routing / deep links).
# The public gallery and per-video pages are server-rendered by the backend
# and only exist on api.openshorts.app. The README has always linked them
# here, where they silently served the landing page instead. Send them to
# the host that actually has them rather than answering with the wrong page.
location /gallery {
return 301 https://api.openshorts.app$request_uri;
}
location /video/ {
return 301 https://api.openshorts.app$request_uri;
}
# index.html must NOT be cached — it points at the hashed asset bundle, so a
# stale cached copy keeps loading the previous deploy's JS. (nginx add_header
# doesn't inherit into a location that sets its own, so the security headers
@ -21,13 +50,25 @@ server {
# (/alternatives/opus-clip and friends) are served at their clean path with a
# 200. Resolving them as directories instead would make nginx 301 to a
# trailing-slash URL, so every canonical would point at a redirect.
#
# Unknown paths get a real 404, not the SPA shell. The app routes entirely
# through the hash (#/pricing, #/auth/callback), which never reaches the
# server, so there is no deep link that needs the fallback — and answering
# 200 with identical markup for every made-up path made the whole site look
# like one page duplicated infinitely to a crawler.
location / {
try_files $uri $uri.html $uri/ /index.html;
try_files $uri $uri.html $uri/ =404;
add_header Cache-Control "no-store, must-revalidate" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
}
error_page 404 /404.html;
location = /404.html {
internal;
add_header Cache-Control "no-store, must-revalidate" always;
}
# Basic security headers.
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;

View file

@ -216,8 +216,9 @@ export function renderPage(page, related = []) {
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>${esc(page.title)}</title>
<meta name="description" content="${esc(page.description)}">
<link rel="canonical" href="${canonical}">
<meta name="robots" content="index,follow,max-image-preview:large,max-snippet:-1">
${page.noindex ? '' : `<link rel="canonical" href="${canonical}">\n`}<meta name="robots" content="${
page.noindex ? 'noindex,follow' : 'index,follow,max-image-preview:large,max-snippet:-1'
}">
<link rel="icon" type="image/png" href="/logo-openshorts.png">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>

View file

@ -66,6 +66,29 @@ ${pages.map((p) => `- [${p.h1}](${SITE.url}${p.path}): ${p.description}`).join('
- [Source code on GitHub](${SITE.repo}): MIT licensed, self-hostable with Docker Compose.
`
const notFoundPage = () => ({
path: '/404',
noindex: true,
title: 'Page not found | OpenShorts',
description: 'That page does not exist on openshorts.app.',
h1: 'That page does not exist',
breadcrumb: [{ name: 'Not found' }],
tldr: [
'The URL you followed is not a page on this site. It may have been a link to the app, which lives at the site root, or to the public gallery, which is served from api.openshorts.app.',
'The links below cover everything openshorts.app actually publishes.',
],
body: `
<h2>Where you probably wanted to go</h2>
<ul>
<li><a href="${SITE.url}/">The app and the landing page</a>, where you can paste a video link and get clips.</li>
<li><a href="/how-openshorts-works">How OpenShorts works</a>, the pipeline stage by stage.</li>
<li><a href="/alternatives">Comparisons</a> against Opus Clip, Klap, Vizard and Submagic.</li>
<li><a href="https://api.openshorts.app/gallery" rel="noopener">The public video gallery</a>, which is served from the API host.</li>
<li><a href="${SITE.repo}" rel="noopener">The source on GitHub</a>, MIT licensed and self-hostable.</li>
</ul>`,
faq: [],
})
export default function seoPlugin() {
const pages = buildPages()
@ -104,6 +127,15 @@ export default function seoPlugin() {
this.emitFile({ type: 'asset', fileName: 'sitemap.xml', source: sitemapXml(pages) })
this.emitFile({ type: 'asset', fileName: 'llms.txt', source: llmsTxt(pages) })
// Served by nginx's error_page for unknown paths. Kept out of `pages` so
// it never reaches the sitemap or llms.txt, and marked noindex, because a
// 404 body that gets indexed is worse than no 404 page at all.
this.emitFile({
type: 'asset',
fileName: '404.html',
source: renderPage(notFoundPage(), relatedFor(pages[0], pages)),
})
},
}
}