
Ever wanted to be able to finally remove the useless /category/ from your WordPress categories permalinks? If yes, read on and get ready to hack your .htaccess file!

Ever wanted to be able to finally remove the useless /category/ from your WordPress categories permalinks? If yes, read on and get ready to hack your .htaccess file!
By default, WordPress category permalinks are displayed that way:
http://www.catswhocode.com/blog/category/wordpress
As you can see, the category in the url is pretty useless. Here's how to remove it:
First backup your .htaccess file. Then, open it and append the following line:
RewriteRule ^category/(.+)$ http://www.yourblog.com/$1 [R=301,L]
Once saved, your categories pages will be displayed like this:
http://www.catswhocode.com/blog/wordpress
Better, isn't it?
81 Responses
Very useful. That is without changing to permalinks on WP admin.
Fantastic tip, JB
I am used to install the “top level categories” plugin to do the same thing…
i have a problem with htaccess file: every time i make a modification on my htaccess file (like this recipe), when i edit a “page” on my WordPress Admin, the htaccess “reverts back” to its original state… is that normal? how can i fix it?
It didn’t work for me. Is that because I’m using permalinks?
I’d prefer to just change the category base on the wp-admin myself rather than code for this.
@Laura: It should works with permalinks, do you have a particular error, or just nothing happens?
@Jean-Baptiste: I don’t have any errors, it just doesn’t work, ‘category’ is still in the url. I have other rules in the file that do work.
Could it be that I’m using a subdomain? I’m so clueless…
I actually like “category” in there – easier to see where you are and easier to filter with robots.txt so search engines don’t index it.
If you want to do the same in plugin format – try Pathless Category Permalinks plugin. It also does 301 redirects for your legacy content so that the search engines will pick up your changes that much faster.
yes,this is very usefull.
Will this work even if I’ve got my posts in blog root also?
I can’t get this to work either.
I tried this aswell:
RewriteRule ^category/(.+)$ http://www.domain.com/blog/$1 [R=301,L]
But the Categories listed at still domain.com/blog/category.
Interesting. However, why wouldn’t you just change the Admin option for the Permalink Base? Can you provide an example of why someone would do it the .htaccess route instead?
How would you do this via Permalinks in the Admin options?
WP doesn’t like having a non-folder for all the blog posts AND for the categories. You can have both or either in a folder (directory) but generally concenscious is WP doesn’t like both.
I think the fear is I can’t have a post called MOVIES and a category called MOVIES since they’ll be the same URL. It just needs to make one a priority and the other gets an extra number on it, just like duplicate post names…
I spent a bit looking for this and just never got what I want, But I’m still looking….
@Spamboy
If the permalink structure for categories is left blank, WordPress will automatically add “/category” to the URL.
@Justin Tadlock You’re correct — sorry for my confusion. You are correct if talking about the Category Base field. What I meant to say is you *can* accomplish the same thing by modifying the “Custom Structure” field to “/%postname%/” instead of the default “/%category%/%postname%/”, even if the Category Base field is blank.
@Lawrence Flynn I’ve done that before with Pages that have like-named slugs as Categories. Wordpress would display the former instead of the latter. Not sure how it would behave with *Posts* instead of *Pages*.
Thanks for the recipes, I like this. but i found a problem with my htaccess file. It’s not only when I try to apply this recipe, but every time i make a modification or change on my htaccess, I’ve some problem there. Maybe people here can show me why is it so and how can I fix the problem? Coz if I still get problem, I can’t add any modification related to htaccess
@Spamboy – that’s not what the rewrite is supposed to do. I have /%postname%/ as the Category Base on my blog and it works as expected with all posts being in the top level directory. But if you were to click on teh actual Category link itself you get taken to /blog/category/whatever. This rewrite should strip that out – but it doesn’t (not for me anyhow).
What I’m trying to achieve is all posts in /blog (done) and all categories displaying as /blog/whatever. Not a huge biggie but I’m kind of fussy like that.
@Laurence Flynn Makes sense now — thanks for the followup!
I tried this on a couple different WordPress site and two different servers and it didn’t work on either one. I also tried the plug-ins that someone said would do the same thing and I would get 404 pages after the /category/ was removed. Looks like I’m just stuck with the /category/ unless any one has an answer to way this isn’t working.
You cook a great recipes
.
I’ve trying to make this hack before, but I never succeed. So now thanks for your recipes. I never think to use htaccess
Not working for me. Tried with and without permalinks?
I found an alternative (plugin) solution:
Decategorizer Plugin:
http://wordpress.org/extend/plugins/decategorizer/installation/
(needs Redirection Plugin:
http://wordpress.org/extend/plugins/redirection/installation/)
Worked for me!
Thanks Laura, it works.
And just to make it a bit clearer.
1) Upload redirection Plugin first.
2) Upload Decategorizer.
3) Activate Redirection
4) Settings are under Tools > Redirection. Just add “category” (without quotes) in the “Source URL” field. Target URL is blank. Save it.
5) Activate Decategorizer.
Voila.
This has come handy, though I had to adopt the code a wee bit to suit my special needs.
In 2.7 at least, going to /blog/categoryname/ works just fine if you have your permalinks set up to be /blog/categoryname/post-title-here/
The only problem is that the automatically generated category links from WP will still have /blog/category/categoryname/
I think you could fix that with a php str_replace() if desired
Unfortunately none of these solutions work completely and I’ve tried everything. The best I could come up with is to remove the %category% tag in the permalinks area. Then you need to manually change the “category” word in the category-template.php file to another word that may be shorter or more useful.
If you use any of the above plugins or hacks, you’ll end up with URLs for categories that don’t work. They will generate without the category word in the URL but they simply won’t work and you’ll get a 404 error. It’s a sad stage for Wordpress.
What’s funny is how timely this fix was, as I was trying to hammer out some URLs on my blog so that categories would represent projects I am working on, all of which I want accessible from the root URL. The combination of the .htaccess Redirect addition and the Pathless Category Permalinks plugin suggested by @Idealien did the trick for me.
But did you try subcategories? All the “tricks” seem to work on level one. But if you add a subcategory then the word ‘category’ is entered right back.
And just to make it a bit clearer.
1) Upload redirection Plugin first.
2) Upload Decategorizer.
3) Activate Redirection
4) Settings are under Tools > Redirection. Just add “category” (without quotes) in the “Source URL” field. Target URL is blank. Save it.
5) Activate Decategorizer.
That’s perfect,
thank you very much
Actually I could never make this work so I gave up.
You also need to change the permalinks internally to point to the new destinations.
Cheers.
What does changing the permalinks internally mean? The pages are what they are and the problem is dynamically. The first level category is fine but not the second, at least from my experience using anything.
Here’s an example. I have two categories, sports and football. But lets assume I have one for right now. Using these methods, the category slug is easily removed:
http://www.mysite.com/sports/game.htm
But if I decided I want to break down my site into subcategories and create a football subcat for sports cat, you end up with:
http://www.mysite.com/category/sports/football/game.com
and that just happens by default. It’s this second level that all these hacks didn’t function. And personally, it makes me a little apprehensive using all this trickery especially with regard to upgrading in the future.
Hi
I have a problem I have copy the line in my .htaccess and it doesn’t delete “category”.
I don’t understant can you help me please ? The order of the line in my .htaccess is important ?
Thank you for your help
kvf300
how to write anything else in the place of word category??
Hi,
Previously I was using a plugin called “Top Level Cats” for the same purpose. When I tried to upgrade WP to the latest version, that plugin started giving problem.
Thanks to your tip, I have now upgraded to WP 2.7.1 and everything is working perfect. Thank you so much.
Thanks soooooo much this worked for me (using Wordpress 2.8)
DeeDee
I meant that the two plugins and the instructions from JQuintana worked.
Found another plugin that does this:
http://wordpress.org/extend/plugins/wp-no-category-base/
I tried the .htaccess hack and it didn’t work for me, but this seems to work.
I just want to change category to Blog (I am using my wp as a cms and need to keep post “separate” from pages)
Why do I do that?
This works for me without editing .htaccess file
Go to Permalink Settings: Custom Structure
/%category%/%postname%/
and edit category base to ./
yes, via WP-ADMIN and permalinks, you can also do it.
cheers
I actually managed to do what i wanted, found it in wordpress site: http://codex.wordpress.org/Making_Your_Blog_Appear_in_a_Non-Root_Folder
Thanks Jean-Baptiste, Angelica and yuryrush.
Editing the htaccess together with ./ as category base in permalinks-settings did the trick.
Thanks.
This seemed too hacky. I did a quick search on the wp extensions site for “no category” and found the first plugin. It worked in less than 30 seconds.
here’s the link, highly recommended:
http://wordpress.org/extend/plugins/wp-no-category-base/
Kenny… Good Choise. Work fine, and don’t lose any link. Installed less than 30 second. Don’t need to modify any file.
On permalink select personal Structured and change
/%category%/%postname%/
for
/%postname%/
If I use this.
I don’t lose all my SEO work during one year, and improve the show of the post.
Thanks all for suggestion. Thanks Kenny for the plugin.
Valentin Yonte
I tried change my .htaccess many times without success and Wp NO Category Base did the work silent and efective.
Thanks guys for share this simple solution.
Put it at the beginning of the .htaccess file. It should work.
Great tip..will really help optimize my site. Thanks
There seems to be some consensus around the following;
1) Best for people %postname%
2) Best for database queries %postid% or year / month
The importance of #2 is that to present a post or comments a database query is made based on key words. If you have a non-keyword component (date, post id) first in your URL this reduces the query time significantly.
The decision has to include the visitors as well as the server resources, especially if the server resources are limited.
Anyone didn’t notice that if someone visit the page of a category… a 404 error code will appear?
xxxxx.com/work/page/2/
that’s the most important problem…
Yes Simone you are right, it does throw a Error 404 page not found. You can change the permalinks to /%category%/%postname%.html and the problem will be resolved.
How can I remove /author/ from my Wordpress URL?
can anyone help?
Anyone didn’t notice that if someone visit the page of a category… a 404 error code will appear?
I guess this is just for people who are already has /%category%/ in the permlink and want to get rid of it and dont want to break anything. For new blog I dont see the need for it, just change the permlink to %postname%.
This is the better. Highly recommended !
http://wordpress.org/extend/plugins/wp-no-category-base/
I test this one: wordpress.org/extend/plugins/wp-no-category-base/
and it works even without this Redirection plugin.
Cheers
Yes Simone you are right, it does throw a Error 404 page not found. You can change the permalinks to /%category%/%postname%.html and the problem will be resolved.
Alright, cool. I’m going to try the plugin first.
Thanks but this doesn;t seem to work on 2.9.1 can you please guide us on how to remove that from in latest version of wp
Works great thanks
Trackbacks: