I want to install something different than wordpress under 'mydomain.com/login', but WordPress automatically redirecting this link '/login' to '/wp-login.php'.

Where can I turn off this redirection?

  • This question is almost similar to what you are asking!!! stackoverflow.com/questions/1976781/… – sri Feb 18 '14 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 Feb 18 '14 at 13:41

If 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.

  function() {
    $requ = untrailingslashit($_SERVER['REQUEST_URI']);
    if (site_url('login','relative') === untrailingslashit( $_SERVER['REQUEST_URI'] )){
      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() ) )

    $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() );

    $logins = array(
        home_url( 'wp-login.php', 'relative' )
    if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $logins ) ) {
        wp_redirect( site_url( 'wp-login.php', 'login' ) );

function remove_default_login_redirect() {
    remove_action('template_redirect', 'wp_redirect_admin_locations', 1000);
    add_action( 'template_redirect', 'custom_wp_redirect_admin_locations', 1000 );


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.