nguyenminh

 

Change login url wordpress

<?php
//////////////////////
// SECURE  WP_ADMIN //
//////////////////////
  // ---- 1.  edit wp-config.php
  /* tells wordpress  what the new directory is, and updates the cookie path.
  define( 'WP_ADMIN_DIR',       'manager' );
  define( 'ADMIN_COOKIE_PATH',  '/' );
  */

  // ---- 2. Url Rewrite
  /* for APACHE
  RewriteRule ^manager/(.*) wp-admin/$1?%{QUERY_STRING} [L]
  RewriteRule ^connect$ wp-login.php
  */
  /* for NGINX
  location ~ ^/ifSubFolder/manager/(.*)$ {
    try_files $uri $uri/ /ifSubFolder/wp-admin/$1;
  }
  location ~ ^/ifSubFolder/connect {
     try_files $uri $uri/ /ifSubFolder/wp-login.php?$args;
   }
   */
  
  // NEXT in functions.php 
  
  // ---- 3. redirects the user if there are trying to reach either of the secure areas.
  if (strpos($_SERVER['REQUEST_URI'], 'wp-admin') !== false || strpos($_SERVER['REQUEST_URI'], 'wp-login') !== false || strpos($_SERVER['REQUEST_URI'], 'admin') !== false || strpos($_SERVER['REQUEST_URI'], 'login') !== false) {
    header("HTTP/1.1 301 Moved Permanently"); 
    header('Location: /ifSubFolder/'); die();
  }
  // ---- 4. replace wp-admin url’s with the proper name.
  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);
  }
  // ---- 5. make sure the login page redirects to the proper page.
  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'];
    }
  }
  // --- 6. function to handle the same issues the wpadmin_filter does with naming.
  add_filter('site_url',  'wplogin_filter', 10, 3);
  function wplogin_filter( $url, $path, $orig_scheme ) {
    $old  = array( "/(wp-login\.php)/");
    $new  = array( "connect");
    return preg_replace( $old, $new, $url, 1);
  }
// END SECURE ADMIN/LOGIN URL

Categorised in: Tổng hợp

0 Comments for "Change login url wordpress"

Leave a Reply

Your email address will not be published. Required fields are marked *