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

Fix builder redirect #1693

Merged
merged 5 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions packages/playground/website-deployment/custom-redirects-lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function playground_handle_request() {
? function ( $str ) { error_log( "PLAYGROUND: $str" ); }
: function () {};

$log( "Handling request for '${_SERVER['REQUEST_URI']}'" );
$log( "Handling request for '{$_SERVER['REQUEST_URI']}'" );

$url = parse_url( $_SERVER['REQUEST_URI'] );
if ( false === $url ) {
Expand Down Expand Up @@ -70,8 +70,8 @@ function playground_handle_request() {
}

if ( $should_redirect ) {
$log( "Redirecting to '${redirect['location']}' with status '${redirect['status']}'" );
header( "Location: ${redirect['location']}" );
$log( "Redirecting to '{$redirect['location']}' with status '{$redirect['status']}'" );
header( "Location: {$redirect['location']}" );
http_response_code( $redirect['status'] );
die();
}
Expand Down Expand Up @@ -188,7 +188,12 @@ function playground_maybe_redirect( $requested_path ) {
);
}

if ( str_ends_with( $requested_path, '/builder' ) ) {
if (
// Since `/builder/` is an actual directory,
// nginx redirects requests for `/builder` to `/builder/`.
str_ends_with( $requested_path, '/builder/' ) ||
str_ends_with( $requested_path, '/builder/index.php' )
) {
return array(
'location' => 'https://playground.wordpress.net/builder/builder.html',
'status' => 301
Expand Down
22 changes: 22 additions & 0 deletions packages/playground/website/builder/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* This file exists so nginx invokes PHP and custom-redirects.php to give
* us a chance to redirect the URI `/builder` to `/builder/builder.html`.
*/
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Navigate to the Blueprint Builder</title>
<!--
ATTENTION: We do not expect this file to be served.
We expect the web server to redirect to the Blueprint Builder instead,
but if it doesn't, this is a fallback.
-->
<meta http-equiv="refresh" content="0; url=builder.html">
</head>
<body>
<a href="builder.html">Navigate to the Blueprint Builder.</a>
</body>
</html>
Loading