WordPress

WordPress Network (MU) URL Rewrite Issue

If you migrate your WordPress website into multi-website network (previously known as WordPress MU) you may get you rewrite rules automatically altered. This will happen in cases when your permalink structure differs from default. All rewrites that have variable prefix like ([0-9]{4})/([0-9]{1,2}) will get some slug added in front. In my case it was «blog/». This is done in purpose to prevent WordPress category slugs to conflict with symlinks of your network websites. This is quite wise of WordPress but only if your network is utilizing directory type URL for your websites. In case you use subdomain structure or even separate domains you might not be happy with this additional token of your URL.

To get rid of it you have to strip this new token directly from the wp_X_options table where X is id of the website you want to strip it for. This is quite handy because you can disable it just for certain websites and also keep this token different for the rest. So pull the required string with the following query:
[php]SELECT * FROM `wp_X_options` WHERE `option_name` = ‹rewrite_rules'[/php] Unfortunately WordPress is keeping its rewrite rules serialized so it would be quite a task too strip this slug from the database directly. Instead you can use the simple script below to unserialize the rewrites array, strip the required slug and serialize it back. Just put your serialized string instead of … and replace «blog» token inside of preg_replace function with your slug.

[php] $str = ‹..›;
$str = unserialize($str);
$new_str = array();
while(list($key, $val) = each($str)){
$new_str[preg_replace(‹/^blog//i›, », $key)] = $val;
}
echo serialize($new_str);
[/php]

Also in the same table find an entry with `option_name` = ‹permalink_structure› and wipe the slug out of there also.

You are done!

Kommentar verfassen

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert