-
-
Notifications
You must be signed in to change notification settings - Fork 571
[5.x] Middleware to redirect absolute domains ending in dot #11782
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
[5.x] Middleware to redirect absolute domains ending in dot #11782
Conversation
I've adjusted this so that it doesn't automatically add the middleware. If you want to use it, you can add it yourself in ->withMiddleware(function (Middleware $middleware) {
+ $middleware->append(\Statamic\Http\Middleware\RedirectAbsoluteDomains::class);
}) It felt too heavy handed to be applied by default. It doesn't feel like the responsibility of the CMS to make such a broad change to your entire application, but I'm happy to make it available to be used. Also, by only applying it to the |
Sounds good! Do we want something added to the docs for this so users know to apply this middleware when running into issues? |
Yeah! We can document it after it's been released. Although, if you're eager, feel free to open a PR on the |
Context: #11714
Domain names ending in dot are completely valid and documented separately in the RFCs
rfc-editor.org/rfc/rfc1035#:~:text=Domain names that end in a dot are called absolute%2C and are taken as complete.
rfc-editor.org/rfc/rfc1034#:~:text=character string which represents a complete domain name (often called "absolute"). For example%2C "poneria.ISI.EDU."
This causes problems when cache is cleared, the homepage is cached with the . suffix. Every user navigating from the homepage will cause every subsequent cache to contain this . suffix, even when users are not navigating to the site with the . suffix
Where the RFC defines it as being the absolute version of the same domain, browsers dealing with CORS do not agree. Causing issues when CORS is used anywhere on the page.
https://statamic.dev./ has the same problem if you visit the site, and open your console you can see it refuses to load the JS. And all internal links are replaced by https://statamic.dev./

This PR introduces an option to redirect domains ending in . to their non . variant e.g. https://example.com./example -> https://example.com/example
preventing urls ending in . from being cached and ensuring the user is sent to a correctly functioning page.
Most major sites seem to deal with it by simply redirecting:
And some do actually break because they don't handle this: