访问 domain.com/login 或 domain.com/admin 等页面时,WordPress 会自动的将链接重定向至wp-login.php, 如果你是将 WordPress 作为底层开发的开发者,或希望不被他人发现你使用 WordPress 程序,这会给你带来诸多不便.
相关重定向代码位于”include/canonical.php”文件中
<?php /** * Redirects a variety of shorthand URLs to the admin. * * If a user visits example.com/admin, they'll be redirected to /wp-admin. * Visiting /login redirects to /wp-login.php, and so on. * * @since 3.4.0 * * @global WP_Rewrite $wp_rewrite */ function wp_redirect_admin_locations() { global $wp_rewrite; if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) ) return; $admins = array( home_url( 'wp-admin', 'relative' ), home_url( 'dashboard', 'relative' ), home_url( 'admin', 'relative' ), site_url( 'dashboard', 'relative' ), site_url( 'admin', 'relative' ), ); if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $admins ) ) { wp_redirect( admin_url() ); exit; } $logins = array( home_url( 'wp-login.php', 'relative' ), home_url( 'login', 'relative' ), site_url( 'login', 'relative' ), ); if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $logins ) ) { wp_redirect( wp_login_url() ); exit; } } ?>
移除它的方法
<?php remove_action('template_redirect','wp_redirect_admin_locations',9999); ?>