Skip to content

Serve index fallback on my.wordpress.net - #3611

Merged
akirk merged 3 commits into
WordPress:trunkfrom
akirk:mywp-index-fallback
May 8, 2026
Merged

Serve index fallback on my.wordpress.net#3611
akirk merged 3 commits into
WordPress:trunkfrom
akirk:mywp-index-fallback

Conversation

@akirk

@akirk akirk commented May 7, 2026

Copy link
Copy Markdown
Member

What?

On my prototype, I redirected 404s to index.html so that my.wordpress.net can be served also for those URLs and then simply restore the URL. Before this PR those URLs lead to a white page instead of loading my.wordpress.net.

Why?

By serving index.html for 404s, it allows to make my.wordpress.net behave like a real WordPress.

How?

The shared WP Cloud redirect handler now falls back to index.html only when HTTP_HOST is my.wordpress.net, after normal file resolution and static-files-to-serve-via-php lookup have both failed. The fallback also checks the deployed static-files-to-serve-via-php/index.html location because deployment may move index.html there for custom cache headers.

Testing

  • php -l packages/playground/website-deployment/custom-redirects-lib.php
  • Verified my.wordpress.net and my.wordpress.net:443 match the host helper, while playground.wordpress.net does not
@akirk
akirk requested review from a team, ashfame and Copilot May 7, 2026 17:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds an SPA-style index.html fallback specifically for my.wordpress.net requests so deep links don’t 404 when no static file / redirect rule matches.

Changes:

  • Add my.wordpress.net host detection (including stripping port) to gate SPA fallback behavior.
  • When path resolution fails for my.wordpress.net, rewrite to /index.html and resolve its deployed location (including static-files-to-serve-via-php/).
  • Introduce helper functions to centralize host matching and index fallback resolution.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +195 to +200
function playground_is_my_wordpress_net_request() {
$host = strtolower( $_SERVER['HTTP_HOST'] ?? '' );
$host = preg_replace( '/:\d+$/', '', $host );

return 'my.wordpress.net' === $host;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@brandonpayton do you know if this would also be my.wordpress.net?

@brandonpayton brandonpayton May 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@akirk I wouldn't know without testing on another WP Cloud site. For this, you could ssh into a WoA site, add a test.php page, and try things out.

But HTTP_HOST should be fine since the hostname is what the WP Cloud request routing uses to identify the site to begin with. If the request makes it to the my.wordpress.net site, it is because the request's Host header matches a domain associated with that site, and my.wordpress.net should be the only domain associated with that particular WP Cloud site.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah, so do you think we could equally well just merge this PR and deploy my.wordpress.net?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think so.

Comment on lines +202 to +210
function playground_resolve_my_wordpress_net_index_fallback() {
$resolved_path = realpath( __DIR__ . '/index.html' );
if ( false === $resolved_path ) {
// Deployment may move index.html aside so PHP can apply custom cache headers.
$resolved_path = realpath( __DIR__ . '/static-files-to-serve-via-php/index.html' );
}

return $resolved_path;
}
Comment on lines +101 to +104
if ( false === $resolved_path && playground_is_my_wordpress_net_request() ) {
$requested_path = '/index.html';
$resolved_path = playground_resolve_my_wordpress_net_index_fallback();
}
@akirk
akirk force-pushed the mywp-index-fallback branch from f4cc6f8 to 4da49c5 Compare May 8, 2026 03:32
@akirk

akirk commented May 8, 2026

Copy link
Copy Markdown
Member Author

I've tried to test-deploy it but the branch protections prevent it, so I guess we'll need to merge it to trunk.

}

if ( false === $resolved_path && ! str_ends_with( $requested_path, '.php' ) ) {
if ( false === $resolved_path && ! str_ends_with( $served_path, '.php' ) ) {

@brandonpayton brandonpayton May 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This looks like a good clarification.

@akirk
akirk force-pushed the mywp-index-fallback branch from 4da49c5 to 1e09001 Compare May 8, 2026 15:20

@brandonpayton brandonpayton left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have not tested this, but it reads well and makes sense to me.

$host = strtolower( $_SERVER['HTTP_HOST'] ?? '' );
$host = preg_replace( '/:\d+$/', '', $host );

return 'my.wordpress.net' === $host;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ignorable nit: If we're already using a regex for replacement, maybe this could be a one-liner regex match on /^my.wordpress.net(:\d+)?$/.

Comment thread packages/playground/website-deployment/custom-redirects-lib.php Outdated
return false;
}

function playground_is_my_wordpress_net_request() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since personal-wp is not the same as the Playground webapp, we may eventually want to fork these deployment-related scripts so customizing my.wordpress.net redirects doesn't introduce any risk to playground.wordpress.net and vice versa.

@brandonpayton

Copy link
Copy Markdown
Member

I'm not sure if WP Cloud nginx config may interfere in any way with a request for a WP path like /wp-admin/, but I think this ought to work.

@akirk
akirk merged commit 0b757c8 into WordPress:trunk May 8, 2026
47 of 52 checks passed
@akirk

akirk commented May 8, 2026

Copy link
Copy Markdown
Member Author

Just cycling back that this works as expected after the deploy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants