How To Remove The /blog/ slug From The Permalinks(URL) in WordPress Multisite Installation Without A Plugin

What is a blog slug? If you have no clue, this post isn’t for you and if you want to know what it is, it is an ugly looking additional “/blog/” in the permalinks(URLs) in your website that comes free with the multisite feature in WordPress. Why ugly? Because it comes uninvited, it’s there and most probably you don’t want it.

How do you remove the additional “blog” in the URL of your posts? Simple, install some plugin which does it for you? That is what I thought; however, before doing so, I just took a careful look at the wp_options table. BAM! There it was. After spending about 30 minutes with settings and checking the data in this table, I have figured out a way to solve the blog slug problem without the need for a plugin. Nope, no need to change a bit of code. You don’t even need to execute any queries. The query and the table values are shown just to indicate what your action does to the database values. It’s a simple process; only step 2 and 3 need your action, you can skip the rest!

Just read on and try it out on your blog. I have also added the explanation(a little that I know). Beware, I haven’t read more than 10 lines of PHP code, so I don’t know what happens in the code but I’m 100% sure on what the end result will be.

EDIT: Mladen put all whys and hows to rest in this comment. Three cheers to the awesome commenter!

Steps to remove blog slug from post links:

  1. Here, I’m assuming that you have your permalinks as /%postname%/ Go to your blog and click on any post. You will notice the blog slug. This is because of the following to two records in wp_options table.

  2. option_id blog_id option_name option_value autoload
    1234 0 permalink_structure /blog/%postname%/ yes
    5678 0 rewrite_rules :77:{s:52:”blog/category/(.+?)/feed/(feed|rdf|rss yes

    Query – SELECT * FROM ‘wp_options’ WHERE ‘option_name’ = ‘permalink_structure’ OR ‘option_name’ = ‘rewrite_rules’


  3. Now, update the Permalink Structure.
    Go to Network Admin » Sites » Move cursor over the main site name(/) » Edit » Settings » Scroll down to Permalink Structure and update it to /%postname%/ and click on Save at the bottom of the page.

    Go to your blog and click on any post, you will notice a 404 – page not found error. This is because the above step only updates permalinks(wp_options.permalink_structure) and the records look like this:

    option_id blog_id option_name option_value autoload
    1234 0 permalink_structure %postname%/ yes
    5678 0 rewrite_rules :77:{s:52:”blog/category/(.+?)/feed/(feed|rdf|rss yes

  4. Update rewrite rules.
    Go to Site » move cursor on main site name(/) » Dashboard » Settings » Permalink. Notice Custom Structure. You will see that blog/ is outside the textbox and %postname%/ appears in the textbox. Do not edit or save anything on this page. Now, the data in the table looks like:

    option_id blog_id option_name option_value autoload
    1234 0 permalink_structure %postname%/ yes
    5678 0 rewrite_rules :77:{s:47:”category/(.+?)/feed/(feed|rdf|rss yes

    What happens is when you visit this page, rewrite_rules gets changed automatically. May be it has something to do with autoload column, I don’t know!

    A few things I noticed:

    • The value updated in step 2, goes to database as is and just to permalink_structure record.
    • Any value updated in step 3, updates both rows mentioned above.
    • WordPress takes the value in the database, removes the “/blog/” substring from it and shows the remaining in the textbox in step 3. The “blog/” shown outside the textbox is kinda fooling you. :P
    • WordPress adds “/blog/” to any value in the textbox updated from step 3 and updates both records in the database.
    • That is the reason, you shouldn’t update the permalinks from the page in step 3; it will automatically get “/blog/” add to the front of it and we will be back to square one.

  5. Visit the blog and click on any post. You should see the post and the permalink(URL) shouldn’t have the “blog slug”. If you still see it or if you are getting 404 error, you have screwed up something. Don’t blame me.
    Antonio left a tip on how to solve the 404s in his comment below. Take a look if need be.

  6. Leave a comment on this blog saying how useful it was or how stupid I really am. If I take a look at the code someday, I will be sure to let you know how exactly it works. If you do know already, what are you waiting for, leave a comment.

Oh, I also noticed that WordPress auto corrects the permalinks(URLs) even if you enter it wrong. For e.g. if your blog post is “example.com/somepost”,, WordPress will take you to the right page even if you enter “example.com/YouCantSeeMe/somepost”!!! It could be that, WordPress uses RegEx or some matching algorithm that compares from right to left and if it finds a match, it will take you to the page even if there are “/.*/” left on the left. Just a guess! Any idea? Check this for more info – How does WordPress handle permalinks?

This entry was posted in Wordpress and tagged , , , , , , , , , . Bookmark the permalink.

71 Responses to How To Remove The /blog/ slug From The Permalinks(URL) in WordPress Multisite Installation Without A Plugin

  1. Rodrigo Pestana says:

    Great workaround! It’s the only one I found that _actually_ works.

    Thanks so much for sharing!

    All the best,
    RP

    • Lobo says:

      I’m glad that you found this useful and also thankful to you for bringing the broken math spam plugin to my notice. I appreciate it.

  2. Nick says:

    This settings remain after WordPress update :)?
    Or with any update… WordPress adds back the “/blog/” slug?

    • Lobo says:

      Oh, I don’t know. I couldn’t test it. However, IMO, an update should not affect my settings, but you never know. Did it fail for you on an update?

  3. Nick says:

    I didn’t try… :) … I already have the last version installed, but the next version 3.2.2 it’s coming soon ;)

    If anyone willing to test it on WP 3.2 and upgrade to 3.2.1… please let me know how it goes…
    Thanks

    • Kisu says:

      Thanks. This saved me a huge amount of work. Usually I prefer the sub-domain network option, but this time, I needed the sub-directory multi site for a project. After migrating an existing single site to a new server and wanting to expand it to multisite, I was able to get a sub-directory install, but got stuck with the /blog/ slug.

      Wish there was something a little more stable. I assume an accidental save on dashboard > settings > permalink would undo this work around and put back the /blog/. By the way, your trick worked in WP 3.3.

  4. webman says:

    I’ve tried following the instructions here but have not succeeded. I am using a single-site WordPress install version 3.2.1. I have a custom permalink structure of

    /%category%/%postname%/

    “blog” does not appear in the mentioned database entries (I’ve checked using phpadmin). And, at the moment, I’m not getting 404-errors (I was earlier).

    What I’m not getting is the blog/ outside of the text box when I go back to the permalink settings page as mentioned in Step 3. What should I do?

    I currently have permalinks like:
    site.com – a non-wordpress index.htm page (site home page)
    site.com/blog – wordpress blog main (home) page
    site.com/blog/categoryname – wordpress category archive
    site.com/blog/tagname – wordpress tag archive
    site.com/blog/categoryname/postname.htm – wordpress post

    What I’m trying to do is remove “blog/” from the last 3 of those to make:

    site.com/categoryname – wordpress category archive
    site.com/tagname – wordpress tag archive
    site.com/categoryname/postname.htm – wordpress post

    Any guidance would be much appreciated.

    Thanks.

    • Lobo says:

      You are not using multisite installation, but a normal install – just like this website you are on. You have installed wordpress in blog directory and hence the url structure. I’d suggest not to do what you are trying to do. It looks difficult to achieve as well.
      Using mod rewrites, redirect all urls with /blog/ to urls without /blog/ and then using rewrite rules at the root directory to redirect the urls with /blog/ but with P (proxy) tag. This should send all site.com/blog/* to site.com/* and when request comes to site.com/*, correct page will be served as the server uses pages at site.com/blog/* without changing the url.
      I haven’t tried and am not sure if this will work and I also don’t know if this affect your seo.

  5. Michael says:

    Thanks for posting this. I was having a lot of trouble getting the permalinks to work properly on a multi-site I’m building and your article got me back on tracks.

    Cheers!

  6. Thanks for figuring this out an sharing it with the world. It’s insane that there is not a more intuitive way to get this done. I understand that the developers are trying to save us from ourselves in case we name a category and a sub-site the same thing, but there should be a better option in the site setup with an explanation to fix this.

    Thanks again!

    • Lobo says:

      I agree that this should have been simpler and an options under Settings would have made everyone’s life easier. Looking at the issue, I don’t think it would be difficult for the developers to fix it.
      Thank you for your encouraging words. :-)

  7. Anita says:

    YES! At my first try I really thought you’re stupid ;-) But in the end I was the stupid one, because I could not believe that I must not re-save the permalinks page.
    But everything is fine – and thanks for your post!!
    Cheers, Anita

    • Lobo says:

      Ha ha ha I think you tried saving it to see if I really meant what I wrote… and btw you have no idea how stupid I really am. ;-)

  8. Dara says:

    It worked great!

    Thank you!

  9. Lobo, many thanks for the tips.

    I just tried this on WordPress 3.2.1 with good success.

    I’m not particularly familiar with interacting with databases via query strings, so just used my host’s phpMyAdmin to browse to the correct table and row and edit the appropriate text in Step 1.

    In Step 2, I wish that Network Admin were a bit more obvious to get to and I also somehow didn’t immediately realize that ‘Settings’ would be under a tab on the page, rather than a subcategory in the left navbar, but once found, that went well.

    Regarding Step 3, I do find it particularly irritating that I am never again to use this admin page ever again. This is, of course, WordPress’ fault and not yours.

    I do appreciate the fact that you spell out what changes we ought to be seeing reflected in the database with each step, but this initially made me think that there were more steps editing the database than there really were.

    Also, in Step 1, I saw so many “blog/” entries in rewrite_rules that I was uncertain as to whether I was to edit them all out manually or not. Thankfully, I chose to only edit the single instance that you cite and the site updated the rest automatically after Step 2.

    Thanks again for the help.

    • Lobo says:

      I think I wasn’t clear enough, if you carefully read the steps you don’t need to write/execute any database queries. The data shown in step 1 is directly from my database table and I just provided the query if anyone needed it. Step 1 is actually read only. Also the database values shown might actually be different if you have a different permalink structure.

      I wish there was a simpler way to do it. I’m glad you were able to get it working.

      • Lobo says:

        I updated the post to mention that three is no need to execute any queries and also mentioned that only step 2 and 3 are necessary… Thank you Nate.

  10. Mladen says:

    I just loved your first paragraph :D.

    Now, why this works?
    Rewrite rules that are used to resolve something like:
    mysite.com/category/uncategorized/page/3
    into
    mysite.com/index.php?category_name=uncategorized&page=3
    are not generated every time WP runs (performance issues), but are fetched from the database (the autoload field tells WP which options to load every time it runs – those that are often needed; it doesn’t have anything to do with the step 3).

    Step 2 (wp-admin/network/site-settings.php?id=1) updates permalink structure (which is then used to generate links for posts), but does not update rewrite rules (that is why after step 2 it doesn’t work). Unexpected, but that’s how it is.

    Step 3. When you visit permalink settings page (wp-admin/options-permalink.php), rewrite rules are flushed. There is a line:
    $wp_rewrite->flush_rules();
    That is executed when you load that page, and it clears/regenerates rewrite rules (using permalink structure from the database, that is the one from the step 2, no /blog there). Why it only works if you don’t save the settings? If you save, during the procedure WP will check if those are rules for the main site in multisite, and if they are (and it’s not a subdomain install), it will spice them with /blog in the front. That part is hardcoded into options-permalink.php (I guess a plugin could use pre_update_option_permalink_structure filter to undo this, but it’s all ugly as you sad).

    So this will work as long as procedure for regenerating rules stays like this (inconsistent). Plugins that flush rewrite rules should not break this (assuming that /blog is forced only in the options-permalink.php procedure), but that should be tested.
    Hope this helps.

  11. Pingback: Removing the /blog Slug in WordPress MultiSite | Jonathan Jeter - UI Expert & Front-End Web Developer

  12. Anna says:

    I’ve used a wordpress template as a website. I don’t really need permalink. But I have this ugly message “Permanent link to this post (42 words, 4 images, estimated 10 secs reading time)” How do I turn permalink off? Or make it invisible. It’s just a website without any archive. Much appreciate your help. Anna.

    • Lobo says:

      I run WordPress too, but haven’t encountered this issue. Please look at the settings page to find if this is enabled from any setting. Also, make sure you aren’t using any plugin that is intentionally displaying this information. Please go to the forums at WordPress support for better visibility.

  13. Pingback: How To Remove The /blog/ slug From The Permalinks(URL) in WordPress Multisite Installation Without A Plugin | Knowledge Base

  14. Emil Uzelac says:

    My Sites > Network Admin > Sites and click on the first one, it’s usually just slash / and you will end up on Edit Site: example.com

    Next step is to click on Settings go down to Permalink Structure and remove blog from /%postname%/ save it and that’s it.

    Go back to you main site and save your permalinks once again, to generate new .htaccess.

    In wp-config.php my multisite setup looks like this:


    /* WP Multisite */
    define('MULTISITE', true);
    define('WP_ALLOW_MULTISITE', true);
    define('SUBDOMAIN_INSTALL', false);
    $base = '/';
    define('DOMAIN_CURRENT_SITE', 'example.com');
    define('PATH_CURRENT_SITE', '/');
    define('SITE_ID_CURRENT_SITE', 1);
    define('BLOG_ID_CURRENT_SITE', 1);

    just in case anyone’s wondering, no special settings whatsoever.

    And please NOTE never ever edit WordPress Core files, not only that you can break your WP install, but changes will be overridden in next WordPress update.

    Thanks,
    Emil

  15. Antonio Lettieri says:

    I tried this and was getting a 404 error for individual blog posts. I then ran this flushed the permalink rules using the $wp_rewrite->flush_rules() method. I stuck this block of code in my functions.php file.

    NOTE: I ran it once then commented it out; it is bad practice to always execute this function.

    • Lobo says:

      Thanks Antonio for the tip. I corrected you comment and deleted the other one. Hope it’s okay. :-)
      I have mentioned this in the post itself. Thanks.

  16. nikhil says:

    I want to remove the tag from my url
    For example: http://www.example/tag/postname.com
    to http://www.example/postname.com
    Please help
    Thanks

    • Lobo says:

      Hi Nikhil,
      I’m not an expert in this area, if you really need help please try WordPress forums or StackExchange fo wordpress. Sorry!

  17. British Curriculum School Kuwait says:

    In this way we can, thank you for your tips.

  18. I’ve only read/executed steps two and three but I can confirm that the steps work as expected.

    I was able to change the “blog” slug or simply remove it.

    Thanks for documenting your research and findings.

  19. marisa says:

    this is an amazing work around.

    thank you!

    genius!

    • Lobo says:

      Anything that works for you. A plugin, as mentioned in that post, better as it gets constant updates and works with any version. Thanks for sharing…

  20. Miha says:

    nikhil:

    You can remove “tag” and “category” base with several plugins, ultimate SEO, yoast SEO, both have this option…

    or use plugins designed for that:
    http://wordpress.org/extend/plugins/wp-no-tag-base/
    http://wordpress.org/extend/plugins/wp-no-category-base/

    Cheers!

  21. Meagan says:

    Interesting spin on this. I’m working with breadcrumbs for a client on their complex multisite website. They didn’t want the breadcrumbs to read “blog” which has led me here. I successfully changed the permalink from “/blog/” to “/wow/” which works for our site – but there was no change in the breadcrumbs.

    So frustrating! If anyone has had to deal with this before let me know if you can help.

    • Mladen says:

      Do you get “blog” in the actual breadcrumb trail (e.g. home>blog>category>title), in the link (href attribute of the anchor tag), or both? I tested this with Breadcrumb NavXT plugin and there was no extra “blog” added. It’s probably an issue with the code generating breadcrumbs (or with some breadcrumb settings). Do you know which plugin/theme is generating breadcrumbs, or is it some custom written code?

  22. Miha says:

    not sure for breadcrumbs, but give it a try with a plugin mention in my comment above…

  23. Pingback: How to Remove /blog Slug from Wordpress MultiSite Permalinks (URL) | QuakeZilla.com

  24. colin says:

    THANK YOU !!! amazing, strange and 100% working, useful fix for a weird problem i was having after migrating multisite to a IIS 7.5 server. I think the server guy had to add loads of hacks and one of them redirected everything to / so pages that had be automatically been placed in /blog/ were getting a 404 error. this fixed it so everything is a mysite.com/ .. ( thanks again !! )

  25. ennan says:

    I found another simpler solution at wordpress.org forum that works OK for me:

    1. At blog site set Settings -> Permalinks -> Common Settings -> Default (Select default only and don’t touch any thing, If you need to change category base, change it in Network Admin)

    2. At Network Admin -> Sites -> (root site) -> settings ->Permalink Structure -> /%category%/%post_id%
    (or whatever you need)

    That it will remove /blog slug

    • Mark says:

      This solution rocks! It’s so easy when you know how! Why doesn’t wordpress make this more intuitive? Thanks for sharing – now I have pretty permalinks on my multisite not ugly permalinks. Thanks.

    • Stig says:

      Thanks, your solution is even better than the one in the article.

  26. Alyssa says:

    Thanks for this method! :)

    I went through the whole 404 error thing and did the replace/reload step. Worked like a charm. And I dare not touch the permalink bit anymore in case the /blog slug appears again.

  27. sir please tell me how i remove extra word from url after html in blogger
    for example
    http://urdumix.blogspot.com/2013/01/wishes-for-valentines-day.html#.UPbRPFJdlkg
    this is my link of my blog after html,( #.UPbRPFJdlkg) these word also shown how i remove these words. i am waiting for your reply thanks!

  28. Amazed says:

    Wow… I have no idea how you stumbled upon this but I couldn’t believe it worked… I feel like I just hacked WordPress or performed some kind of witch craft… haha thanks!

  29. Exactly where did you obtain the concepts to compose ““How To Remove The /blog/ slug From The Permalinks(URL) in WordPress Multisite Installation Without A Pluginlearn(n*share(n,learn(n+1)))”?

    Many thanks -Nick

  30. Jeb says:

    This worked for me! Step 2 edit and the step 3 “visit” no edit mystery.

  31. Wesam Alalem says:

    You’re the best ;) Looking for this for ages. thank you.

  32. Pingback: Ten Things Every WordPress Pro Should be Framiliar With | George Spake

  33. Pingback: Note to self: Reload db table after messin with Permalinks | Sigg3.net - Just another weblog

  34. Ashutosh says:

    Thanks a ton Buddy !!.. For such a fabulous working step by step solution. I’m grateful to you. Live Long & Prosper :-)

  35. Pingback: UPGRADE: Reload db table after messin with Permalinks | Sigg3.net - Just another weblog

  36. George Spake says:

    I know this post is kind of old but it still applies. I’ve used this odd trick to fix permalink issues on several different sites. I don’t know what kind of magic happens when you visit that permalinks page in the admin panel but I’m glad it works. I spent 2 days trying to get permalinks to work with custom post types and taxonomies and then I remembered reading this a while back, clicked on permalinks in the admin panel and bam everything works. THANKS!

  37. Goutham says:

    It worked. Still it is a weakness in the multi-system setup with sub-directory structure. What if someone else starts a new site with the category name used in the first site under domain name\

  38. dillu says:

    thank to your help

  39. Thanks, this really helped.

  40. Koby says:

    Everything is very open with a precise clarification of the issues.
    It was definitely informative. Your site is extremely helpful.
    Thanks for sharing!

  41. Ayumi says:

    This worked perfectly after my third attempt (The first couple of times i hit ‘save’ on step 3) So it serves me right for reading your information too quickely !

  42. Everything said was very reasonable. But, what about this?
    what if you added a little content? I am not suggesting your information is not good,
    but suppose you added a title that grabbed folk’s attention?

    I mean How To Remove The /blog/ slug From The Permalinks(URL) in WordPress Multisite Installation Without A
    Pluginlearn(n*share(n,learn(n+1))) is a little vanilla.

    You might peek at Yahoo’s home page and watch how they
    write post titles to get people to open the links.

    You might try adding a video or a picture or two to get people excited about what you’ve got to
    say. In my opinion, it would bring your posts a little livelier.

  43. Pingback: ...A definitive way to get rid of the annoying multisite blog slug problem?

  44. Pancho says:

    Hi,

    Thanx for the post. But I need to do something that is the oposit of your post title :P
    What I want is to add the /blog in the subsiste blog post permalinks, I mean:

    domain.com/my-post-title <- OK

    domain.com/subsite1/blog/my-subsiste-post-title <- NOT WORK

    The question is. Is this possible? becasue if I do that change in the subsite permalink, I try to use only /%postname%/ in the permalink but this makes the posts always shows the front-page.php template and not single.php template.

    Also found the /blog is reserved to the main site :( and can´t find a guide or tutorial to explain if is possible to do what I want using the htaccess or some rewrite code in the funtions.php

    Any idea? thanx for any help :)

  45. aditya says:

    WOOW that was really amazing man….worked like charm for me!!

  46. Rob says:

    Fantastic! Very easy to follow directions, and the fix worked beautifully! Thank you so much!

  47. fred says:

    YOU JUST NEED TO DO
    STEP 2 FIRST, then STEP 1

    THATS IT

  48. Jaseer says:

    This is the latest issue, I found a good article here to solve this issue, and it worked for me, you can also try
    http://www.zaliyo.com/how-to-remove-permalink-blog-in-wordpress-multisite/

  49. legal advise says:

    When I originally commented I clicked the “Notify me when new comments are added” checkbox
    and now each time a comment is added I get several emails with the same comment.
    Is there any way you can remove people from that service?
    Thanks!

    • Lobo says:

      Hi, I apologize for the inconvenience. I use a plugin to enable that option and it has behaved properly in all cases. I’m not sure what happened. In the email you get, there is a manage subscription link. You may use it to manage your subscriptions. You can also do it from http://praveenlobo.com/techblog/comment-subscriptions/ link. Your email is not on the list for any subscription currently. Thanks for letting me know.

Leave a Reply

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


four + 6 =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Notify me of followup comments via e-mail. You can also subscribe without commenting.