docs: add Apache and Nginx examples for adapter-static#15692
Open
aymenhmaidiwastaken wants to merge 2 commits into
Open
docs: add Apache and Nginx examples for adapter-static#15692aymenhmaidiwastaken wants to merge 2 commits into
aymenhmaidiwastaken wants to merge 2 commits into
Conversation
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
|
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') |
Contributor
There was a problem hiding this comment.
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
teemingc
reviewed
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.htaccessrewrite rules for direct subpage navigationtry_filesconfiguration with static asset cachingtrailingSlash: 'always'andtrailingSlash: 'never'modesWhen deploying SSG sites to traditional hosting via FTP, direct navigation to URLs like
/aboutfails with a 404 because the server doesn't know to look for/about/index.htmlor/about.html. These examples solve that.Closes #15150