Skip to content

[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

Merged

Conversation

indykoning
Copy link
Contributor

@indykoning indykoning commented May 12, 2025

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.

Domain names that end in a dot are called
absolute, and are taken as complete. Domain names which do not end in a
dot are called relative;

rfc-editor.org/rfc/rfc1034#:~:text=character string which represents a complete domain name (often called "absolute"). For example%2C "poneria.ISI.EDU."

a character string which represents a complete domain name (often called "absolute"). For example, "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./
image

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:

@jasonvarga jasonvarga changed the title [5.x] Redirect absolute domains ending in . to regular domain [5.x] Middleware to redirect absolute domains ending in dot May 13, 2025
@jasonvarga
Copy link
Member

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 bootstrap/app.php.

 ->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 web middleware, it wouldn't work when accessing the CP. It should be applied application-wide.

@indykoning
Copy link
Contributor Author

Sounds good! Do we want something added to the docs for this so users know to apply this middleware when running into issues?

@duncanmcclean
Copy link
Member

Yeah! We can document it after it's been released. Although, if you're eager, feel free to open a PR on the docs repo and we can merge it.

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.

4 participants