Change Wordpress Admin URL
Here's an article from wordpress's site.
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 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); }
Add below line to .htaccess file
RewriteRule ^secret-folder/(.*) wp-admin/$1?%{QUERY_STRING} [L]
I played around with this and there is a much simpler way to do this all in this one simple function below without having to muck around with anything else (create unnecessary folders, redirects, pages, etc.).
// Simple Query String Login page protectionfunction 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');
This is very helpful topic. I made some little correction in the function and this is my version:
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); }
Mainly for redirecting of wp-admin
.
And most important part:
add_rewrite_rule( '^' . 'backend/(.*)','wp-admin/$1?%{QUERY_STRING}' );
To updates .htaccess
rule.