Howto remove /blog/ from permalinks URL in Wordpress MU

If you are using multi-user version of wordpress, then the main (or root) blog has default permalink URL prefix '/blog', which is not possible to change to anything else. This prefix is hardcoded in php files of wordpress system - the main reason is, that if you are using sub-directories as a blog adresses (like http://domain.tld/blogname), wordpress needs to know, if the requested URL belongs to main blog or to some of sub-blogs. In this case I do not recommend changing this behaviour.

But if your wordpress installation is configured to use sub-domain blog structure, you have to edit two files of your wordpress instance. This fix works on Wordpress MU version 1.2.4 and on older version 1.2.2 as well. I hadn't try any other versions but I suppose, that it should work similar on different version of Wordpress (just try to search for '/blog' in your Wordpress .php files). Before any of these changes backup your original files!The first file is index-install.php and it is located in root directory. You have to change line #412 like from this:

update_blog_option( 1, 'permalink_structure', '/blog/%year%/%monthnum%/%day%/%postname%/');

To this:

update_blog_option( 1, 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/');

The second file is located in /wp-admin directory and the name is options-permalink.php. First change is on line #68, replace this:

$permalink_structure = '/blog' . $permalink_structure;

With this:

$permalink_structure = '/blog' . $permalink_structure;

Second line which has to be changed is on line #152 - replace folowing:

: domain.$current_site->path == $current_blog->domain.$current_blog->path ) { echo "/blog"; $permalink_structure = str_replace( "/blog", "", $permalink_structure ); }?>

With this:

[sourcecode language='html']

: domain.$current_site->path == $current_blog->domain.$current_blog->path ) { $permalink_structure = str_replace( "/blog", "", $permalink_structure ); }?>

Now log into your Wordpress system, go into Options -> Permalinks and choose your prefered option - then press Update permalink structure and check URL of your posts.

Comments