Skip to content

Commit b91dc9c

Browse files
authored
Redirect the default REST prefix (#5)
1 parent 2e5edf7 commit b91dc9c

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

content/plugins/f-api/inc/namespace.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function bootstrap() : void {
2727

2828
// Register our own rewrites.
2929
add_action( 'init', __NAMESPACE__ . '\\register_rewrites' );
30+
add_action( 'parse_request', __NAMESPACE__ . '\\redirect_old_namespace', 0 );
3031

3132
Events\bootstrap();
3233
}
@@ -44,3 +45,14 @@ function register_rewrites() : void {
4445
add_rewrite_rule( '$', 'index.php?rest_route=/', 'bottom' );
4546
add_rewrite_rule( '^(.*)?', 'index.php?rest_route=/$matches[1]', 'bottom' );
4647
}
48+
49+
/**
50+
* Redirect the wp-json default prefix.
51+
*/
52+
function redirect_old_namespace() : void {
53+
if ( strpos( $_SERVER['REQUEST_URI'], '/wp-json/' ) !== false ) {
54+
$new_url = substr( $_SERVER['REQUEST_URI'], 8 );
55+
wp_safe_redirect( rest_url( $new_url ), 301 );
56+
exit;
57+
}
58+
}

0 commit comments

Comments
 (0)