WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] redirect guest who are not logged in to HTTP 404 page instead of worpress error

[Resolved] redirect guest who are not logged in to HTTP 404 page instead of worpress error

  • I am designing my wordpress website and I want nobody should know that I am using wordpress for my site. I designed my custom login page with custom URL and managed my logged in users to get HTTP 404 error if they try to access wp-admin or wp-login but only thing left is that if a guest who is not logged in try to access wp admin by simply typing http://www.mydomain/wp-admin on browser gets wordpress error which reveals everything. So I need a code so those guests also get HTTP 404 error. They should be redirected 404 page only because I set a ban for those users who get more than 5 HTTP error. Anyone please help.

Viewing 15 replies - 1 through 15 (of 20 total)
  • Use your .htaccess to handle 404’s.

    ErrorDocument 404 /404.html

    *Insert this before WordPress’ rules.

    It doesn’t work. I have inserted it in root directory .htaccess. But it shows in the page “please login to continue” and in address bar it shows like this “http://mydomain.com/redirect_to=http%3A%2F%2Fmydomain.com%2Fwp-admin%2F&reauth=1”. I am not getting what I expected. Is there any code to redirect users who are not logged in to 404 page if they try to access wp-admin. I did for logged in users except administrator with this code
    add_action(‘admin_init’, ‘no_mo_dashboard’);
    function no_mo_dashboard() {
    global $wp_query;
    if (!current_user_can(‘manage_options’) && $_SERVER[‘DOING_AJAX’] != ‘/wp-admin/admin-ajax.php’) {
    $wp_query->set_404();
    status_header( 404 );
    get_template_part( 404 ); exit();
    }
    }

    which redirects all users except administrator.

    I inserted this code in functions.php

    I see. You can use the conditional is_user_logged_in

    I did it also gives me the same result.

    You did what? Post the updated code so I can see.

    And Put code in between backticks. Please.

    if ($_SERVER['DOING_AJAX'] != '/wp-admin/admin-ajax.php' && !is_user_logged_in()) {
      $wp_query->set_404();
      status_header( 404 );
      get_template_part( 404 ); exit();
      }
    }

    Am I doing it right?

    add_action('admin_init', 'no_mo_dashboard');
    function no_mo_dashboard() {
      global $wp_query;
      if (!current_user_can('manage_options') && !is_user_logged_in() && $_SERVER['DOING_AJAX'] != '/wp-admin/admin-ajax.php') {
      $wp_query->set_404();
      status_header( 404 );
      get_template_part( 404 ); exit();
      }
    }

    also did that

    Your &&’s are making it not work. Precedence isn’t being set correctly. In that statement, all three have to be true. Have you tried it like this:

    function no_mo_dashboard() {
    		    global $wp_query;
    
    		    // if ajax request is being made, or administrator, return
    		    if( (defined('DOING_AJAX') && DOING_AJAX ) || current_user_can( 'manage_options' ) )
    		  		return;
    
    			$wp_query->set_404();
    			status_header( 404 );
    			get_template_part( 404 ); exit();
    		}

    I am getting a syntax error with that. sorry

    Moderator kmessinger

    @kmessinger

    I am designing my wordpress website and I want nobody should know that I am using wordpress for my site.

    All they have to do is look at the source code to see it is WordPress.

    Its not the point. Point is if someone break the rules i should redirct them to error page so that he could be banned because i set a ban limt for that error.

    Moderator Andrew Nevins

    @anevins

    Forum moderator

    What rules are they breaking?

Viewing 15 replies - 1 through 15 (of 20 total)
  • The topic ‘[Resolved] redirect guest who are not logged in to HTTP 404 page instead of worpress error’ is closed to new replies.
Skip to toolbar