Last active
February 23, 2022 23:33
-
-
Save cee-chen/2a584505f58eac20f08c8ac6f927e702 to your computer and use it in GitHub Desktop.
Apache .htaccess / https / barba.js / Jekyll workaround
This file contains 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
# Apache servers throw content mismatch errors with XMLHttpRequests (used by barba.js) | |
# because links without a trailing slash didn't know to look for a subdir/index.html. | |
# See: | |
# https://discuss.emberjs.com/t/mixed-content-the-page-was-loaded-over-https-but-requested-an-insecure-xmlhttprequest-endpoint/13876/10 | |
# https://stackoverflow.com/questions/43696438/strange-mixed-content-issue | |
# https://serverfault.com/a/817023 | |
# https://webmasters.stackexchange.com/questions/105111 | |
# Disable the default directory slash behavior and handle that ourselves below | |
DirectorySlash Off | |
# If this .htaccess is located within a subdir (e.g., `foo.com/bar/.htaccess`), | |
# AllowNoSlash is required to make `foo.com/bar` not 403, and -Indexes is for security. | |
RewriteOptions AllowNoSlash | |
Options -Indexes | |
# This will correctly and silently rewrite `foo.com/bar/baz` to `foo.com/bar/baz/index.html` | |
# (but only if the requested `baz` directory has an `index.html` inside it). | |
RewriteEngine On | |
RewriteCond %{REQUEST_FILENAME} -d | |
RewriteCond %{REQUEST_URI} !/$ | |
RewriteCond %{REQUEST_FILENAME}/index.html -f | |
RewriteRule (.*) $1/index.html [L] |
Glad someone had a use for this! 😄
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this solution! I have been looking for a long time to be able to reproduce dynamically generated URLs statically 1:1 without a trailing slash.