WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] redirect guest who are not logged in to HTTP 404 page instead of worpress error (21 posts)

  1. piko00001
    Member
    Posted 6 months ago #

    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.

  2. Christian1012
    Member
    Posted 6 months ago #

    Use your .htaccess to handle 404's.

    ErrorDocument 404 /404.html

    *Insert this before WordPress' rules.

  3. piko00001
    Member
    Posted 6 months ago #

    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.

  4. piko00001
    Member
    Posted 6 months ago #

    I inserted this code in functions.php

  5. Christian1012
    Member
    Posted 6 months ago #

    I see. You can use the conditional is_user_logged_in

  6. piko00001
    Member
    Posted 6 months ago #

    I did it also gives me the same result.

  7. Christian1012
    Member
    Posted 6 months ago #

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

  8. Christian1012
    Member
    Posted 6 months ago #

    And Put code in between backticks. Please.

  9. piko00001
    Member
    Posted 6 months ago #

    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();
      }
    }
  10. piko00001
    Member
    Posted 6 months ago #

    Am I doing it right?

  11. piko00001
    Member
    Posted 6 months ago #

    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

  12. Christian1012
    Member
    Posted 6 months ago #

    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();
    		}
  13. piko00001
    Member
    Posted 6 months ago #

    I am getting a syntax error with that. sorry

  14. kmessinger
    Volunteer Moderator
    Posted 6 months ago #

    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.

  15. piko00001
    Member
    Posted 6 months ago #

    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.

  16. Andrew
    Forum Moderator
    Posted 6 months ago #

    What rules are they breaking?

  17. kmessinger
    Volunteer Moderator
    Posted 6 months ago #

    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.

    But then how will you log in? You will get the same error.

    typing http://www.mydomain/wp-admin on browser gets wordpress error which reveals everything

    There is no error until the user actually trys to log in. And then it reveals very little.

  18. Christian1012
    Member
    Posted 6 months ago #

    I am getting a syntax error with that. sorry

    What is the syntax error?

  19. piko00001
    Member
    Posted 6 months ago #

    Parse error: syntax error, unexpected $end in /home/u279486952/public_html/wp-content/themes/mytheme/functions.php on line 477

  20. piko00001
    Member
    Posted 6 months ago #

    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.
    But then how will you log in? You will get the same error.
    typing http://www.mydomain/wp-admin on browser gets wordpress error which reveals everything
    There is no error until the user actually trys to log in. And then it reveals very little.

    I have a custom login page for all users and after login it shows error for all users other than administrator.

  21. piko00001
    Member
    Posted 5 months ago #

    I have done it with Lockdown wp plugin. Thank God

Reply

You must log in to post.

About this Topic