Multisite wordpress and subdomain URL collisions

I have a multisite WordPress installed on a server using a domain, site.com and I have a subdomain setup in WordPress, so subsites are at sub1.site.com, sub2.site.com etc.

In addition to this, the main site has other services in subfolders that are not related to WordPress, such as site.com/something.

Everything is working fine, except that when a customer on a subsite uses permalinks by post name, and uses the same title as one of the main site’s subfolders, it goes to the main site’s subfolder; for example sub1.site.com/something goes to the same place as site.com/something.

Is there anything I can do (by editing .htaccess or httpd.conf?

Or should I just move WordPress to it’s on subfolder in main site (site.com/wordpress) to prevent these URL collisions?

1 Answer
1

You could just prevent slugs matching existing directories. There are two filters for that.

Example, not tested:

add_filter( 
    'wp_unique_post_slug_is_bad_hierarchical_slug', 
    'prevent_directory_slugs', 
    10, 
    2 
);
add_filter( 
    'wp_unique_post_slug_is_bad_flat_slug', 
    'prevent_directory_slugs', 
    10, 
    2 
);

function prevent_directory_slugs( $bool, $slug )
{
    return is_dir( ABSPATH . "https://wordpress.stackexchange.com/" . $slug );
}

Leave a Comment