I want to install something different than wordpress under 'mydomain/login', but WordPress automatically redirecting this link '/login' to '/wp-login.php'.
Where can I turn off this redirection?
I want to install something different than wordpress under 'mydomain/login', but WordPress automatically redirecting this link '/login' to '/wp-login.php'.
Where can I turn off this redirection?
Share Improve this question asked Feb 18, 2014 at 12:37 marekmarek 231 silver badge3 bronze badges 2- This question is almost similar to what you are asking!!! stackoverflow/questions/1976781/… – sri Commented Feb 18, 2014 at 13:33
- Please do a bit more search on this site and I am sure you will find a solution for this problem... – sri Commented Feb 18, 2014 at 13:41
2 Answers
Reset to default 5If you look at canonical.php
you will notice that the wp_redirect_admin_locations
function is hooked very late-- at priority 1000. This means that just about any function hooked to redirect_canonical
runs before this one. So, conditionally remove wp_redirect_admin_locations
from the template_redirect
hook.
add_action(
'template_redirect',
function() {
$requ = untrailingslashit($_SERVER['REQUEST_URI']);
if (site_url('login','relative') === $requ ){
remove_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );
}
}
);
This answer is based on the findings of “login” in permalink redirects to wp-login.php wp3.6
Disable "/login" redirect
As already stated there the relevant code is located at the very end in /wp-includes/canonical.php
You need to remove the default "wp_redirect_admin_locations" and replace it with a slightly modified custom version. Add this to your function.php file.
function custom_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' )
);
if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $logins ) ) {
wp_redirect( site_url( 'wp-login.php', 'login' ) );
exit;
}
}
function remove_default_login_redirect() {
remove_action('template_redirect', 'wp_redirect_admin_locations', 1000);
add_action( 'template_redirect', 'custom_wp_redirect_admin_locations', 1000 );
}
add_action('init','remove_default_login_redirect');
Why this might not even be necessary
Also you should be aware that the redirect only applies if there is nothing else at /login. As soon as e.g. you create a page /login the redirect doesn't apply any more. (See /wp-includes/canonical.php:553 for where this happens.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742335065a4424487.html
评论列表(0条)