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

Website: Fix deploy-time check for file with PHP-handled redirect #1350

Merged
merged 1 commit into from
Apr 30, 2024
Merged
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
35 changes: 26 additions & 9 deletions packages/playground/website-deployment/custom-redirects-lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,25 @@ function playground_handle_request() {
//
$redirect = playground_maybe_redirect( $requested_path );
if ( false !== $redirect ) {
$log( "Redirecting to '${redirect['location']}' with status '${redirect['status']}'" );
header( "Location: ${redirect['location']}" );
http_response_code( $redirect['status'] );
die();
$should_redirect = true;
if ( isset( $redirect['condition']['referers'] ) ) {
$should_redirect = false;
if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
foreach ( $redirect['condition']['referers'] as $referer ) {
if ( str_starts_with( $_SERVER['HTTP_REFERER'], $referer ) ) {
$should_redirect = true;
break;
}
}
}
}

if ( $should_redirect ) {
$log( "Redirecting to '${redirect['location']}' with status '${redirect['status']}'" );
header( "Location: ${redirect['location']}" );
http_response_code( $redirect['status'] );
die();
}
}

//
Expand Down Expand Up @@ -159,12 +174,14 @@ function playground_maybe_redirect( $requested_path ) {
);
}

$has_dotorg_referrer = isset( $_SERVER['HTTP_REFERER'] ) && (
str_starts_with( $_SERVER['HTTP_REFERER'], 'https://developer.wordpress.org/' ) ||
str_starts_with( $_SERVER['HTTP_REFERER'], 'https://wordpress.org/' )
);
if ( $has_dotorg_referrer && str_ends_with( $requested_path, '/wordpress.html' ) ) {
if ( str_ends_with( $requested_path, '/wordpress.html' ) ) {
return array(
'condition' => array(
'referers' => array(
'https://developer.wordpress.org/',
'https://wordpress.org/',
),
),
'location' => '/index.html',
'status' => 302,
);
Expand Down
Loading