5

I want to change the login url of my Wordpress install away from /wp-admin.php

I am aiming to do so and am looking at changing the .htaccess file to add in:

RewriteRule ^login$ http://yourdomain.com/wp-login.php [NC, L]

From what I gather however, going to /wp-admin will still allows people to login using that link. I was thinking of doing some sort of PHP redirect so that when the user types in /wp-admin it goes to the 404 not found page.

What is the best way to change the login URL without using a plugin and with the highest security standards?

3
  • 1
    I tink it is much better if you create a custom login page.
    – cybmeta
    Sep 3 '14 at 21:27
  • Creating a custom login page does not give you the option to change the URL. It only allows you to change the look and certain parameters. Sep 3 '14 at 23:02
  • Well, that is not fully true. You still have to send the login form data to wp-login.php, and wp-loning.php direct URL is still available (it is also with .htaccess RewriteRule), but you can use the URL you want for the login page. Just set it up when you create the page as you do with any other page in Wordpress. Maybe you have not fully read the link I posted. Not sure what your goal is but custom login page satisfies the custom URL aspect, plus you can fully customize it.
    – cybmeta
    Sep 4 '14 at 6:47
5

About changing the login url, i already did by mysel. It help me protect my site and prevent brute force You can change it in htaccess. But you also need to add the filter to replace old login url in wordpress. Example to my website: File .htaccess:


RewriteRule ^signin(.*) wp-login.php?%{QUERY_STRING}

In your theme or custom plugin, you can add the filter to make sure wordpress show the correct login url .


add_filter( 'login_url', 'my_login_page', 10, 2 );
function my_login_page( $login_url, $redirect ) {
    return str_replace("wp-login.php","signin",$login_url);
}

add_action( 'login_form', 'replace_login_submit_form',1); 
function replace_login_submit_form() {
  $your_content = ob_get_contents();
  $your_content = str_replace("wp-login.php","signin",$your_content);  
  ob_get_clean();
  echo $your_content;
}

Hope it can help you!

1
  • doesn't work..tried it.
    – abhij89
    Apr 29 at 12:14
5

There is no sane reason or method to do this "without a plugin", because the code necessary to accomplish the job should be contained within a plugin.

Don't roll your own code, use a tried and tested plugin that is designed specifically for the job. That is the secure way.

0
0

This can be possible by creating a all new similar file to your existing wp-login.php file. Steps need to follow:

Suggestion: Take a backup of wp-admin.php file before follow the below instruction.

  • Open Your wordpress install location, if it is root just look for file called wp-login.php
  • Now, create a new php file and name it as your new login url i.e. if you want to make your login url www.yoursite.com/iamgaurav instead of www.yoursite.com/wp-admin, so create the new file named: iamgaurav.php
  • Now copy the all codes of existing wp-login.php file & paste it in your new file iamgaurav.php
  • Change all existing instances of wp-login to iamgaurav (easy by bulk replacement option through any editor)
  • Now save this file and remove the original wp-login.php file from root.

You are done. Clear your cache and check the login with new url: www.yoursite.com/iamgaurav

You will get 404 error in case anyone try to login by www.yoursite.com/wp-admin

Hope it helps.

Thanks

2
  • 2
    No. No. Don't alter any of the core files.
    – De Coder
    Aug 26 '18 at 9:11
  • If you are going to recommend changing the core files (which you should not at all), AT LEAST have the decency to clarify the problems that this solution conceives
    – Raba
    Dec 20 '19 at 8:57
0

Add this code in functions.php after that you will not be able to access your page at https://www.thebetacoders.com/wp-admin
Now you will be able to access your page at https://www.thebetacoders.com/wp-login.php?customtext


Change $new_login variables according to your needs.

<?php

function redirect_to_nonexistent_page()
{

  $new_login =  'customtext';
  if (strpos($_SERVER['REQUEST_URI'], $new_login) === false) {
    wp_safe_redirect(home_url('NonExistentPage'), 302);
    exit();
  }
}
add_action('login_head', 'redirect_to_nonexistent_page');

function redirect_to_actual_login()
{

  $new_login =  'customtext';
  if (parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY) == $new_login && ($_GET['redirect'] !== false)) {
    wp_safe_redirect(home_url("wp-login.php?$new_login&redirect=false"));
    exit();
  }
}
add_action('init', 'redirect_to_actual_login');
-1

You can use this code:

add_action('init','custom_login');

function custom_login(){
 global $pagenow;
 if( 'wp-login.php' == $pagenow && $_GET['action']!="logout") {
  wp_redirect('http://YOURSITE.com/URL');
  exit();
 }
}
3
  • 1
    Please add some comments to this. It's bad practise to not give some explanation to answers. Apr 2 '18 at 20:08
  • 2
    this is a redirect, not a new login url.
    – Tritof
    Feb 23 '19 at 12:16
  • this is not the answer what is asked for. Jan 24 at 17:35

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