htaccess rewrite for author query string when WP is in subfolder

The question is about doing this with .htaccess, but why not disabling author pages from within WordPress instead?

This would achieve the same result while making the subdirectory concern irrelevant altogether (and also works regardless of permalink structure settings)

Sample code that sets all urls to author pages to a 404 error:

add_action( 'template_redirect',
        function() {
                if ( isset( $_GET['author'] ) || is_author() ) {
                        global $wp_query;
                        $wp_query->set_404();
                        status_header( 404 );
                        nocache_headers();
                }
        }, 1 );
add_filter( 'author_link', function() { return '#'; }, 99 );
add_filter( 'the_author_posts_link', '__return_empty_string', 99 );

(code taken from this plugin: Disable Author Archives)

Leave a Comment