The following code works and is clear, but it's also verbose. I suspect that there's a way to make it more terse, so that it could be skimmed quickly and it'd be more obvious what's happening.
// The functions return either `false`, or a valid URL.
$redirect = site_redirects( $domain, $_SERVER['REQUEST_URI'] );
if ( ! $redirect ) {
$redirect = get_city_slash_year_url( $domain, $_SERVER['REQUEST_URI'] );
}
if ( ! $redirect ) {
$redirect = unsubdomactories_redirects( $domain, $_SERVER['REQUEST_URI'] );
}
if ( ! $redirect ) {
$redirect = get_canonical_year_url( $domain, $path );
}
if ( $redirect ) {
header( 'Location: ' . $redirect );
}
As an example, here's something I tried that didn't work:
$redirect =
site_redirects( $domain, $_SERVER['REQUEST_URI'] ) ||
get_city_slash_year_url( $domain, $_SERVER['REQUEST_URI'] ) ||
unsubdomactories_redirects( $domain, $_SERVER['REQUEST_URI'] ) ||
get_canonical_year_url( $domain, $path )
;
...but that just returns true
or false
, instead of the first truthy return value.
I know it'll vary somewhat from language to language, but I'm curious if there's a common pattern, or at least something common to C-based languages.