Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert .htaccess files to use _headers and _redirects. #855

Draft
wants to merge 16 commits into
base: 11ty
Choose a base branch
from

Conversation

BigBlueHat
Copy link
Member

@BigBlueHat BigBlueHat commented Mar 27, 2025

This PR implements the _headers and _readirects files used by Cloudflare (and many others) to handle simple
header additions and redirects. These files are simpler formats than Apache HTTPD's .htaccess and can
be trivially used as documentation for other header and redirect formats (should the need arise).

Copy link

cloudflare-workers-and-pages bot commented Mar 27, 2025

Deploying json-ld-org with  Cloudflare Pages  Cloudflare Pages

Latest commit: 52b351d
Status: ✅  Deploy successful!
Preview URL: https://5a9791b2.json-ld-org.pages.dev
Branch Preview URL: https://convert-htaccess-to-cf-files.json-ld-org.pages.dev

View logs

@BigBlueHat BigBlueHat force-pushed the convert-htaccess-to-cf-files branch from 113d763 to 772636c Compare March 27, 2025 21:30
@BigBlueHat BigBlueHat changed the base branch from main to 11ty March 31, 2025 14:10
@@ -0,0 +1,15 @@
/playground-dev /playground 302

/contexts/schema.org.jsonld http://schema.org/ 301
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/contexts/schema.org.jsonld http://schema.org/ 301
/contexts/schema.org.jsonld https://schema.org/ 301

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah...I was trying to avoid making any changes to the routing during this PR...but we probably should fix all the http:// destinations... I may do that in a final pass commit on this PR.

Copy link
Member

Choose a reason for hiding this comment

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

Note that http://schema.org/ and https://schema.org are different, as all of the classes and properties get the scheme from the source file. Typically, and historically, we use the 'http' version.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know what we should be doing for ids in data. But in this case, their server will redirect to https anyway, so might as well avoid that extra step. It's possible the redirect here predates them supporting https and/or hosting a context file. I'm also not sure where this endpoint is used anymore

Copy link
Member

Choose a reason for hiding this comment

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

The commit link referred to in d3d3ecf isn't working for me. Should that have been 5828deb? I imagine there are few relevant links out there related to this. Mostly in historical pre 2011 emails I'd guess.

Copy link
Member Author

Choose a reason for hiding this comment

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

Weird. Not sure why the SHA was different... Maybe a copy/paste fail. I'll update the commit message. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually looks like a stray b wandered into the URL... Likely me VIMing faster than I should. It'll be fixed when I next push an update.

@BigBlueHat BigBlueHat force-pushed the convert-htaccess-to-cf-files branch from 772636c to 2f9629c Compare March 31, 2025 18:11
@davidlehn
Copy link
Member

These redirects and headers are hard to check manually or visually. There should be a regression test so these don't break. If not now, should create an issue for it.

@BigBlueHat
Copy link
Member Author

These redirects and headers are hard to check manually or visually. There should be a regression test so these don't break. If not now, should create an issue for it.

Yeah, I went looking for some easy thing to do that testing with earlier...but everything requires hoisting up significant test framework mess. I may craft a small one-off JS file to do them instead.

Cloudflare already supports the `.jsonld` extension properly (along with
any/all other registered file exstensions).

Cloudflare also turns CORS on by defualt for all origins.
The `images/README.md` was already handled, so the only addition to the
ignores list is the `images/Makefile`.
This one never did what it intended to, judging by the commit it
was added during:
5828deb
Some handled slashes, some did not. These should match what was
previously in place.
CSS and images were not loading previously.
Sadly, Cloudflare currently only does content negotiation for images.
However, the Pages Functions Middleware option is more than sufficient
to handle the mapping and loading based on simple Accept header values.

NOTE: the current implementation *is not* robust and only handles single
value Accept headers.
This commit uses code generated by a Google AI Overview result. They cite
no sources and claim no license. However, it is exactly what I was looking
for with that search.
@BigBlueHat BigBlueHat force-pushed the convert-htaccess-to-cf-files branch from 2f9629c to 52b351d Compare March 31, 2025 18:48
@BigBlueHat BigBlueHat requested a review from davidlehn March 31, 2025 18:48
@BigBlueHat
Copy link
Member Author

@davidlehn I've not written a test script yet, but this should be ready in all other ways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants