How do I prefix blog post urls as mysite.com/blog/%postname%/ but allow authors to still be located at mysite.com/authors/%nicename%?

I’ve tried a bunch of things but cannot find a solution that works.

I want my site to have the structure:

mysite.com/ = homepage
mysite.com/blogs/ = blog archive
mysite.com/blogs/year/ = blog archive (in a specific year)
mysite.com/blogs/year/month/ = blog archive (in a specific month)
mysite.com/blogs/year/month/postname = blog post
mysite.com/authors/ = authors archive
mysite.com/authors/nicename = author profile
mysite.com/customposttype/ = custom post type archive
mysite.com/customposttype/postname = custom post type post

Currently, with /blogs/%year%/%month%/%postname%/ set as the permalink structure, everything works correctly except the authors part. It forces it to mysite.com/blogs/authors/ and mysite.com/blogs/authors/nicename, which is not desireable, since most authors will be making custom post types and not blogs.

Some posts I checked here but without the right answer:

How to properly prefix blog post URL's

Permalinks Question: Adding a prefix ONLY in front of the posts

Possible to change the URL for the regular post type without affecting the URL of other custom post types?

Solutions Collecting From Web of "How do I prefix blog post urls as mysite.com/blog/%postname%/ but allow authors to still be located at mysite.com/authors/%nicename%?"

You can set the author base independently by manipulating the $wp_rewrite global:

function wpa55976_author_base() {
    global $wp_rewrite;
    $wp_rewrite->author_base = 'authors';
    $wp_rewrite->author_structure = '/' . $wp_rewrite->author_base . '/%author%';

    // EDIT - rewrite rule to force author urls to resolve:
    add_rewrite_rule('authors/([^/]+)/?$', 'index.php?author_name=$matches[1]', 'top');

}
add_action( 'init', 'wpa55976_author_base' );

Make sure to visit your permalinks page to flush rewrites after you add this.

The one thing you won’t get is mysite.com/authors/ = authors archive, as WordPress doesn’t provide this page by default, though you may be able to create an authors page and use a custom template, or add a rewrite rule to handle it.