Skip to content

docs: add Apache and Nginx examples for adapter-static#15692

Open
aymenhmaidiwastaken wants to merge 2 commits into
sveltejs:mainfrom
aymenhmaidiwastaken:docs/adapter-static-apache-nginx-examples
Open

docs: add Apache and Nginx examples for adapter-static#15692
aymenhmaidiwastaken wants to merge 2 commits into
sveltejs:mainfrom
aymenhmaidiwastaken:docs/adapter-static-apache-nginx-examples

Conversation

@aymenhmaidiwastaken
Copy link
Copy Markdown

Summary

  • Add Apache .htaccess rewrite rules for direct subpage navigation
  • Add Nginx try_files configuration with static asset caching
  • Cover both trailingSlash: 'always' and trailingSlash: 'never' modes
  • Include precompressed file serving examples (brotli/gzip)

When deploying SSG sites to traditional hosting via FTP, direct navigation to URLs like /about fails with a 404 because the server doesn't know to look for /about/index.html or /about.html. These examples solve that.

Closes #15150

Add rewrite rules for Apache (.htaccess) and Nginx (try_files) so that
direct navigation to subpages works on traditional web servers. Includes
examples for both trailingSlash modes, precompressed file serving, and
static asset caching.

Closes sveltejs#15150
@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 9, 2026

⚠️ No Changeset found

Latest commit: 79122f7

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@svelte-docs-bot
Copy link
Copy Markdown

Comment on lines +199 to +207
# If the request is for an existing file or directory, serve it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Try appending /index.html (works with trailingSlash: 'always')
RewriteCond %{REQUEST_FILENAME}/index.html -f
RewriteRule ^(.*)$ $1/index.html [L]

# Try appending .html (works with trailingSlash: 'never')
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# If the request is for an existing file or directory, serve it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Try appending /index.html (works with trailingSlash: 'always')
RewriteCond %{REQUEST_FILENAME}/index.html -f
RewriteRule ^(.*)$ $1/index.html [L]
# Try appending .html (works with trailingSlash: 'never')
# Try appending /index.html (works with trailingSlash: 'always')
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}/index.html -f
RewriteRule ^(.*)$ $1/index.html [L]
# Try appending .html (works with trailingSlash: 'never')
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

Apache mod_rewrite conditions incorrectly structured - !-f and !-d conditions only applied to first RewriteRule, not to the second rule for .html files

Fix on Vercel

@teemingc teemingc added the documentation Improvements or additions to documentation label May 6, 2026
Comment thread documentation/docs/25-build-and-deploy/50-adapter-static.md Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Docs: Add Apache/Nginx examples for SSG sites (adapter-static)

2 participants