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

Subdirectory compatibility #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ function handle_redirect() {
}
$path = $site->path;
// Use blogs table domain as the primary domain
redirect( $domain . $path );
redirect( $domain . $path, $site );
}

/**
Expand All @@ -123,7 +123,7 @@ function legacy_redirect() {
// Check the blog domain isn't a subdomain or subfolder
if ( false === strpos( $site->domain, get_current_site()->domain ) ) {
if ( $_SERVER['HTTP_HOST'] !== $site->domain ) {
redirect( $site->domain . $site->path );
redirect( $site->domain . $site->path, $site );
}

return;
Expand All @@ -142,8 +142,7 @@ function legacy_redirect() {
// Redirect to the first active alias if we're not there already
if ( $_SERVER['HTTP_HOST'] !== $mapping->get_domain() ) {
$domain = $mapping->get_domain();
$path = $mapping->get_site()->path;
redirect( $domain . $path );
redirect( $domain, $mapping->get_site() );
} else {
break;
}
Expand All @@ -155,9 +154,10 @@ function legacy_redirect() {
*
* @param string $url
*/
function redirect( $url ) {
function redirect( $url, $site ) {
$status_code = (int) apply_filters( 'mercator.redirect.status.code', 301 );
$domain = untrailingslashit( set_url_scheme( "http://{$url}" ) );
wp_redirect( $domain . esc_url_raw( $_SERVER['REQUEST_URI'] ), $status_code );
$path = preg_replace( '/^' . preg_quote( $site->path, '/' ) . '/i', '/', $_SERVER['REQUEST_URI'] );
wp_redirect( $domain . esc_url_raw( $path ), $status_code );
exit;
}