admin管理员组

文章数量:1289497

I've successfully made wp-admin not accessible (redirected to 404 page) here is the codes in my function file:

add_filter('site_url', 'wpadmin_filter', 10, 3);

function wpadmin_filter( $url, $path, $orig_scheme ) {
    $old = array( "/(wp-admin)/");
    $admin_dir = WP_ADMIN_DIR;
    $new = array($admin_dir);
    return preg_replace( $old, $new, $url, 1);
}


function redirect_wp_admin(){
    $redirect_to = $_SERVER['REQUEST_URI'];
    if(count($_REQUEST)> 0 && array_key_exists('redirect_to', $_REQUEST)){
        $redirect_to = $_REQUEST['redirect_to'];
        $check_wp_admin = stristr($redirect_to, 'wp-admin');
        if($check_wp_admin){
            wp_safe_redirect( '404.php' );
        }
    }
} 

and the htaccess:

RewriteRule ^controlpanel/(.*) wp-admin/$1?%{QUERY_STRING} [L]

Now the confusing part is I have no idea how to do the same thing for wp-login.php. the changing from "wp-login.php" to "access" works but when wp-login.php typed, it is still accessible

here's the code in the function file:

add_filter('site_url',  'wplogin_filter', 10, 3);

function wplogin_filter( $url, $path, $orig_scheme )
{
 $old  = array( "/(wp-login\.php)/");
 $new  = array( "access");
 return preg_replace( $old, $new, $url, 1);
}

htaccess file:

RewriteRule ^access$ wp-login.php

So, my question is what to do to make wp-login.php not accessible (either redirected to 404 page or anything)?

Any answers are very appreciated :)

Thank you very much in advance

I've successfully made wp-admin not accessible (redirected to 404 page) here is the codes in my function file:

add_filter('site_url', 'wpadmin_filter', 10, 3);

function wpadmin_filter( $url, $path, $orig_scheme ) {
    $old = array( "/(wp-admin)/");
    $admin_dir = WP_ADMIN_DIR;
    $new = array($admin_dir);
    return preg_replace( $old, $new, $url, 1);
}


function redirect_wp_admin(){
    $redirect_to = $_SERVER['REQUEST_URI'];
    if(count($_REQUEST)> 0 && array_key_exists('redirect_to', $_REQUEST)){
        $redirect_to = $_REQUEST['redirect_to'];
        $check_wp_admin = stristr($redirect_to, 'wp-admin');
        if($check_wp_admin){
            wp_safe_redirect( '404.php' );
        }
    }
} 

and the htaccess:

RewriteRule ^controlpanel/(.*) wp-admin/$1?%{QUERY_STRING} [L]

Now the confusing part is I have no idea how to do the same thing for wp-login.php. the changing from "wp-login.php" to "access" works but when wp-login.php typed, it is still accessible

here's the code in the function file:

add_filter('site_url',  'wplogin_filter', 10, 3);

function wplogin_filter( $url, $path, $orig_scheme )
{
 $old  = array( "/(wp-login\.php)/");
 $new  = array( "access");
 return preg_replace( $old, $new, $url, 1);
}

htaccess file:

RewriteRule ^access$ wp-login.php

So, my question is what to do to make wp-login.php not accessible (either redirected to 404 page or anything)?

Any answers are very appreciated :)

Thank you very much in advance

Share Improve this question asked Sep 17, 2013 at 10:19 WannabeWannabe 112 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

Instead of filtering the site_url you should be filtering adim_url and login_url

add_filter('admin_url', 'new_admin_url');

function new_admin_url()
{
    // Insert the new URL here:
    return get_bloginfo('url').'/controlpanel/';
}

add_filter( 'login_url', 'new_login_url', 10, 2 );
function new_login_url( $login_url, $redirect ) {
    return get_bloginfo('url').'/access/';
}

And combine with the Rewrite Rules and redirections in the .htaccess. For example, for the wp-login.php (I'm not a mod_rewrite expert, so it is really possibly the next code doesn't work or need some modifications):

// Internal Rewrite from access to wp-login
RewriteRule ^access(.*)$ wp-login.php$1 [NC,L]

// Real redirection from wp-login to access appending the query string
RewriteCond %{REQUEST_URI} ^wp-login.*
RewriteRule ^ access$ [R=301,NC,QSA,L]

本文标签: How to make wploginphp not accessible