0

Is there a way to set wp-admin at domain-root? usually you got to wp-admin @ domain.com/wp-admin I would like to have wp-admin at domain.com

Is this doable and is it done with Htaccess or what is needed?

roseri
  • 11
  • 1
    please explain clearly – charan kumar Sep 11 '18 at 06:46
  • 1
    Usually when you entering a website you goes to the frontend at domain.com. But i would like to get to the wp-admin when I'm entering domain.com, without /wp-admin being displayed in the url. – roseri Sep 11 '18 at 13:43
  • `wp-admin` is a subfolder in the standard WordPress installation. If you want to redirect your user to that folder immediately upon accessing the domain root, you can indeed do that using `.htaccess.` – Justin R. Sep 11 '18 at 18:20
  • 1
    How can you achieve that with .htaccess? – roseri Sep 12 '18 at 06:24

2 Answers2

0

I'm not quite sure what you mean by have /wp-admin at your domain root, but you can use this in your theme's functions.php to force a log-in to view the website.

// Force user login before viewing website
function force_login()
{
    if ( ! is_user_logged_in() )
    {
        if ( is_feed() )
        {
            $credentials = array();
            $credentials['user_login'] = $_SERVER['PHP_AUTH_USER'];
            $credentials['user_password'] = $_SERVER['PHP_AUTH_PW'];

            $user = wp_signon( $credentials );

            if ( is_wp_error( $user ) )
            {
                header( 'WWW-Authenticate: Basic realm="' . $_SERVER['SERVER_NAME'] . '"' );
                header( 'HTTP/1.0 401 Unauthorized' );
                die();

            } 

        } 

        else
        {

            header( 'Location: /wp-admin' );
            die();

        }

    } 

} 

add_action( 'template_redirect', 'force_login' );
  • My question is more about getting the url to wp-admin to be domain root. Usually when you entering a website you goes to the frontend at domain.com. But i would like to get to the wp-admin when I'm entering domain.com, without /wp-admin being displayed in the url – roseri Sep 11 '18 at 13:44
0

You can do redirect from domain.com/wp-admin to domain.com

but the problem is after you logged in, the url will land on wp-admin/posts.php etc., which will redirect it to domain.com again.

By this way it will create a redirect loop which will turn breaking the wp-admin.

I think its a bad idea, instead you can create a custom login page and set it as a homepage.

charan kumar
  • 2,119
  • 2
  • 20
  • 26