//
you're reading...
Wordpress

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:

<p id="customstructure"><?php _e('Custom structure'); ?>: <?php if( $current_site->domain.$current_site->path == $current_blog->domain.$current_blog->path ) { echo "/blog"; $permalink_structure = str_replace( "/blog", "", $permalink_structure ); }?><input name="permalink_structure" id="permalink_structure" type="text" class="code" style="width: 60%;" value="<?php echo attribute_escape( $permalink_structure ); ?>" size="50" /></p>

With this:

<p id="customstructure"><?php _e('Custom structure'); ?>: <?php if( $current_site->domain.$current_site->path == $current_blog->domain.$current_blog->path ) { $permalink_structure = str_replace( "/blog", "", $permalink_structure ); }?><input name="permalink_structure" id="permalink_structure" type="text" class="code" style="width: 60%;" value="<?php echo attribute_escape( $permalink_structure ); ?>" size="50" /></p>

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.

Discussion

2 thoughts on “Howto remove ‘/blog’ from permalinks URL in WordPress MU

  1. hh.. interesting.

    Posted by orepEvodo | May 4, 2009, 4:57 pm

Trackbacks/Pingbacks

  1. Pingback: Permalinks, Link Rot, Google PR: A Solution To The Nightmare | Bui4Ever.com | Richard Bui - August 14, 2008

Leave a comment

Your email address will not be published. Required fields are marked *