Change Wordpress Admin URL

I changed the structure of my Wordpress a bit. Here is what I have:

define('WP_SITEURL', 'http://' . $_SERVER['SERVER_NAME'] . '/wordpress');
define('WP_HOME',    'http://' . $_SERVER['SERVER_NAME']);
define('WP_CONTENT_DIR', dirname(__FILE__) . '/content');
define('WP_CONTENT_URL', 'http://' . $_SERVER['SERVER_NAME'] . '/content');

So, I have a content directory that contains my plugins and themes. And then I have a wordpress directory that contains the main WP files, minus the wp-content folder.

With this new structure, I have to access the WP backend with this URL: http://site.dev/wordpress/wp-admin

Is there a way to change it so that I can just access it like this: http://site.dev/wp-admin

I do not want Wordpress to be in the url. Will it be the htaccess update that I need to do, or is there a parameter that I can use in my wp-config.php file?

+12
source share
6 answers

Here is an article from wordpress.

http://wordpress.org/support/topic/how-to-change-the-admin-url-or-wp-admin-to-secure-login

  • Add constant to wp-config.php

    define('WP_ADMIN_DIR', 'secret-folder');  
    define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . WP_ADMIN_DIR);  
    
  • Add the filter below to functions.php

    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);  
    }
    
  • Add the line below to the .htaccess file

    RewriteRule ^secret-folder/(.*) wp-admin/$1?%{QUERY_STRING} [L]
    
+18
source

I communicated with this, and there is a much simpler way to do this in this simple simple function below, without having to extinguish anything else (create unnecessary folders, redirects, pages, etc.).

// Simple Query String Login page protection
function example_simple_query_string_protection_for_login_page() {

$QS = '?mySecretString=foobar';
$theRequest = 'http://' . $_SERVER['SERVER_NAME'] . '/' . 'wp-login.php' . '?'. $_SERVER['QUERY_STRING'];

// these are for testing
// echo $theRequest . '<br>';
// echo site_url('/wp-login.php').$QS.'<br>';   

    if ( site_url('/wp-login.php').$QS == $theRequest ) {
        echo 'Query string matches';
    } else {
        header( 'Location: http://' . $_SERVER['SERVER_NAME'] . '/' );
    }
}
add_action('login_head', 'example_simple_query_string_protection_for_login_page');
+3
source

. , :

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

 function wpadmin_filter( $url, $path, $orig_scheme ) {
    $request_url = $_SERVER['REQUEST_URI'];

    $check_wp_admin = stristr($request_url, 'wp-admin');
    if($check_wp_admin){
        wp_redirect( home_url( '404' ), 302 );
        exit();
    }

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

wp-admin.

:

add_rewrite_rule( '^' . 'backend/(.*)','wp-admin/$1?%{QUERY_STRING}' );

.htaccess .

+2

, , /wp-admin ( public_html/wordpress) public_html , , , WordPress ( wordpress_test, ) example.com/wp-admin - , example.com/wordpress/wp-admin.

, , wp-admin - , WP wp-admin . php . , , .

: . wp-admin, , .

+1

wp-.

, wp-admin, , , "worksersneeded/"

, SSL, - .

Notepad ++: https://notepad-plus-plus.org/download/

.

WordPress .

wp-admin. : "workingneeded" .

" ", " ": wp-admin/

" "

.

wp-config.php , :

ini_set('log_errors',TRUE);
ini_set('error_reporting', E_ALL);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');

, WordPress, wp-admin "workingneeded", , , WordPress.

error_log.txt.

. , .php, wp-admin. , wp-admin .

, , notepad++. , .

wp-content wp file manager.

, WordPress , WordPress. .

WordPress 4.9.8, 5.0.3

5.0.3 error_log.txt. .

0

- WP CORE ( - ).

1- wp-login.php new-secret-url.php ( )

2- new-secret-url.php / wp-login.php new-secret-url.php

3- Add the following code to your functions.php:

/** Hide default login */
add_action( 'init', 'marounmelhem_hide_login' );
function marounmelhem_hide_login() {

    //Only proceed for guests
    if ( ! is_user_logged_in() ) {

        //Getting current page
        $current_url   = str_replace( '/', '', $_SERVER['REQUEST_URI'] );
        $hiddenWpAdmin = 'new-secret-url'; //Change this to your new secret wp-admin url
        $redirectNaTo  = '/';

        //Checking if accessing correct login url
        if ( $current_url == $hiddenWpAdmin ) {
            wp_redirect( '/'.$hiddenWpAdmin.'.php' );
            exit;
        }

        //Only allow requests to wp-login.php coming from correct login url
        $adminToCheck = [
            'wp-admin',
            'wp-login.php'
        ];
        if (
            in_array( $current_url, $adminToCheck )
            &&
            $_GET['action'] !== "logout"
        ) {
            wp_redirect( $redirectNaTo );
            exit();
        }
    }
}

4- This only works if you are not using any other login forms, if you do, you can change:

is_user_logged_in()- possibly !current_user_can( 'subscriber' )(or the role specified in the logon logic in the web interface)

5- Not sure if ajax calls work with the above, please let me know if you tried this

0
source

Source: https://habr.com/ru/post/1543626/


All Articles