WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [closed] How to change the admin url or wp-admin to secure login (13 posts)

  1. Sandip Patil
    Member
    Posted 2 years ago #

    Steps:

    1. Add constant to wp-confing.php

    define('WP_ADMIN_DIR', 'secret-folder');
    define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . WP_ADMIN_DIR);

    2. Add below filter 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);
     }

    3. Add below line to .htaccess file
    RewriteRule ^secret-folder/(.*) wp-admin/$1?%{QUERY_STRING} [L]

    Done...!!!

    Now your admin URL will be like: http://www.yourdomain.com/secret-folder/

  2. jpisanu
    Member
    Posted 2 years ago #

    Hi there! This would be SUCH A GREAT solution. I came here forwarded by a question I made on Stackoverflow.

    I followed this step by step but still being able to log through /wp-admin and my "secret-folder" shows a 404.

    Any ideas?

    Thanks!

  3. Sandip Patil
    Member
    Posted 2 years ago #

    It works fine for me... Check below code for each file..

    .htacess code:

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

  4. jpisanu
    Member
    Posted 2 years ago #

    Hi there, thanks again for answer me.
    I just followed your structure, I realized that it is working but in a different way I imagined.
    On the initial question I wanted to change the login URL. In this case, if your type your site URL/wp-admin you will still getting the login form, my idea was to move everything to a different path, show a 404 if anyone puts /wp-admin on your site.

    What I found here is that my dashboard is now showing the site.com/secret-folder URL once logged in, but the login form is still shown under /wp-admin and if you type site.com/secret-folder I get a 404.

    Best.

  5. Sandip Patil
    Member
    Posted 2 years ago #

    Put slash at the end of url..
    e.g. : site.com/secret-folder/

  6. skatemic
    Member
    Posted 1 year ago #

    Is there a way to make /wp-admin inaccessible and have /secret-folder/ as the only way to access the login page?

  7. Sandip Patil
    Member
    Posted 1 year ago #

    Yes above code allow you to implement the admin login for url..
    site.com/secret-folder/

    and below code will restrict the URL : site.com/wp-admin

    add_action('login_form','redirect_wp_admin');

    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' );
    }
    }
    }

  8. gungwah
    Member
    Posted 1 year ago #

    On which file do i put above code??

  9. greyblok
    Member
    Posted 1 year ago #

    This doesnt seem to be working for me. I tried using example.com/admin and it redirects me to example.com/wp-admin

    Which parts of the code do I edit?

    define('WP_ADMIN_DIR', 'admin');
    define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . WP_ADMIN_DIR);
    add_filter('http://www.example.com',  '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);
     }

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

    This is how I edited the code

  10. Kevin Ryman
    Member
    Posted 1 year ago #

    I have the same issue a greyblok, whenever I try going to I tried using example.com/admin I get redirected to example.com/wp-admin...

    Also, when adding the code OP posted (to functions.php), I get the following error message:

    Fatal error: Call to undefined function add_filter() in /home1/*****/public_html/site.com/wp-includes/functions.php on line 11

    Thoughts?

  11. Bagladyb
    Member
    Posted 1 year ago #

    Hello everyone, I currently have a wordpress.com blog now I want to change it over to wordpress.org to be included with my website. I have downloaded .org however I can not figure out how to login wpadmin where do I find this.

  12. esmi
    Forum Moderator
    Posted 1 year ago #

    @Bagladyb: As per the Forum Welcome, please post your own topic. Posting in an existing topic prevents us from being able to track issues by topic. Added to which, your problem - despite any similarity in symptoms - is likely to be completely different.

  13. Bagladyb
    Member
    Posted 1 year ago #

    Sorry new to this thanks

Topic Closed

This topic has been closed to new replies.

About this Topic