I really like the idea of using .htaccess
rewrite rules in combination with the /.well-known/
folder for keeping my webspace tidy and coherently / consistently organised.
For instance, I know that webcrawlers (and humans)
- will look for my
robots.txt
in the root folder; and - will look for my
security.txt
in the/.well-known/
folder.
This means that files which ought to be near each other would, conventionally, be separated.
The Setup
But I also know I can rewrite requests using .htaccess
, such that I can rewrite a request for:
/robots.txt
to/.well-known/protocols/robots.txt
/.well-known/security.txt
to/.well-known/protocols/security.txt
Great. Now all the protocols:
and maybe even:
can live together.
But what about sitemap.xml
and serviceworker.js
?
So far, so good.
But what if, analagously, I want to have something like:
/.well-known/sitemaps/sitemap.xml
/.well-known/serviceworkers/serviceworker.js
I know I can use .htaccess
to rewrite requests for /sitemap.xml
and /serviceworker.js
, but I also know that these files are location-sensitive.
That is, the directives in each of these files are only supposed to apply to files:
- in the same folder; and
- in subfolders of that folder
See:
The location of a Sitemap file determines the set of URLs that can be included in that Sitemap. A Sitemap file located at http://example.com/catalog/sitemap.xml can include any URLs starting with http://example.com/catalog/ but can not include URLs starting with http://example.com/images/.
and:
The service worker will only catch requests from clients under the service worker's scope. [...] The max scope for a service worker is the location of the worker.
Source: https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers
But what is the sensitive location in this context?
Is it the "location" as it appears in the filepath request, or is it the actual filesystem location?
robots.txt
they may have trouble locating it or try to create a new one assuming that one does not exist./robots.txt
and/.well-known/security.txt
) is only a correctly formatted URL Path. As such - and fairly ironically, given that I was originally setting out to find a way to put all protocol files and other meta documents in the/.well-known/
folder - I've now ditched the/.well-known/
folder entirely and moved all the meta documents into subfolders like/.assets/theme/meta/protocols/
and/.assets/theme/meta/sitemaps/
.