Skip to content

Instantly share code, notes, and snippets.

@cee-chen
Last active February 23, 2022 23:33
Show Gist options
  • Save cee-chen/2a584505f58eac20f08c8ac6f927e702 to your computer and use it in GitHub Desktop.
Save cee-chen/2a584505f58eac20f08c8ac6f927e702 to your computer and use it in GitHub Desktop.
Apache .htaccess / https / barba.js / Jekyll workaround
# 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]
@cee-chen
Copy link
Author

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