block wordpress 'author' page

Asked

Viewed 85 times

0

Friends, I am trying to block via htaccess when someone tries to access the wordpress 'author' page ( http://meusite.com.br/? Author=1 )... I thought this solution presented here at the forum would work, but it didn’t... does anyone have any solution via htaccess for this? obgdo

The solution I found here on the forum was:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?site_exemplo.com.br$ [NC]
RewriteRule ^(noticias/como-bloquear-acesso-a-pagina) - [L,F]
  • Hello, one solution would be to redirect to another page, or to the home page.

  • that’s exactly what my htacces does, send it to the main page when it encounters error type 404, so I want the author page to give error 404

  • it would not be simpler to hide the Author page if you do not want it to be displayed?

  • actually do not know how to hide (if you can indicate any link about it here from the forum), but I believe that if you had some way via htaccess, could be used for other similar cases, that perhaps can not be 'hidden'...

  • gives a mess in this (material)[https://br.support.wordpress.com/paginas/visibilidade-da-pagina/] I think it can help you, have plugins that do this

  • ah yes... that I already know, but for this page of 'Author' there is no way to use this function...

  • I tried to use this but it gives syntax error, can anyone try to see if it works? https://wordpress.2bearstudio...Able-wordpress-Author-pages/

  • i tried this on htaccess Rewritecond %{QUERY_STRING} (Author= d+) [NC] Rewriterule . * - [F] , but fell on the apache test page... '

  • I got it! The solution I used was the one I pointed out at the beginning... Rewriteengine On Rewritecond %{HTTP_HOST} (www.)? site_example.com.br$ [NC] Rewriterule (news/how-block-access-to-page) - [L,F] only needed to adjust the final path... ps.: I don’t know how to close a topic, but this can already be closed

  • was just as I expected http://ineclub.com.br/? Author=1

Show 5 more comments

2 answers

0

See if this helps you, it’s done right in functions.php

// Disalbe access to author page
add_action('template_redirect', 'my_custom_disable_author_page');

function my_custom_disable_author_page() {
    global $wp_query;

    if ( is_author() ) {
        $wp_query->set_404();
        status_header(404);
        // Redirect to homepage
        // wp_redirect(get_option('home'));
    }
}
add_action( 'template_redirect', 'remove_author_pages_page' );

The magic happens when using the is_author() function, if you want to see the list of all functions for each page go to: https://codex.wordpress.org/Conditional_Tags

0

Add this to the . htaccess file, it will redirect all author requests looking for a number (Author ID) to the home page:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI}  ^/$
RewriteCond %{QUERY_STRING} ^/?author=([0-9]*) [NC]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/? [L,R=301,NC]
</IfModule>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.