Post Pic

How to: Remove /category/ from your WordPress url

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

Jan 08 2009 10:07

Very useful. That is without changing to permalinks on WP admin.

Jan 08 2009 11:05

Fantastic tip, JB :)
I am used to install the “top level categories” plugin to do the same thing…

Jan 08 2009 11:27

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?

Jan 08 2009 12:04

It didn’t work for me. Is that because I’m using permalinks?

Jan 08 2009 13:16

I’d prefer to just change the category base on the wp-admin myself rather than code for this.

Jan 08 2009 13:54

@Laura: It should works with permalinks, do you have a particular error, or just nothing happens?

Jan 08 2009 14:01

@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…

Jan 08 2009 14:12

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.

Jan 08 2009 15:03

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.

Jan 08 2009 18:26

yes,this is very usefull.

Jan 09 2009 02:08

Will this work even if I’ve got my posts in blog root also?

Jan 09 2009 02:22

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.

Jan 09 2009 05:36

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?

Jan 09 2009 08:18

How would you do this via Permalinks in the Admin options?

Jan 09 2009 08:31

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….

Jan 09 2009 11:17

@Spamboy
If the permalink structure for categories is left blank, WordPress will automatically add “/category” to the URL.

Jan 09 2009 14:39

@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*.

Jan 09 2009 14:55

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

Jan 09 2009 15:06

@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.

Jan 09 2009 17:01

@Laurence Flynn Makes sense now — thanks for the followup!

Jan 11 2009 01:42

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.

Jan 11 2009 05:42

You cook a great recipes :D .
I’ve trying to make this hack before, but I never succeed. So now thanks for your recipes. I never think to use htaccess :D

Jan 20 2009 20:15

Not working for me. Tried with and without permalinks?

Jan 26 2009 22:25

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!

Jan 28 2009 05:49

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. :)

Jan 28 2009 09:48

This has come handy, though I had to adopt the code a wee bit to suit my special needs.

Feb 01 2009 23:27

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

Feb 08 2009 16:45

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.

Feb 09 2009 04:00

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.

Feb 09 2009 06:49

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.

Mar 16 2009 08:13

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

Mar 16 2009 15:19

Actually I could never make this work so I gave up.

Mar 18 2009 02:06

You also need to change the permalinks internally to point to the new destinations.

Cheers.

Mar 19 2009 13:41

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.

Mar 21 2009 10:20

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

Apr 28 2009 19:43

how to write anything else in the place of word category??

May 30 2009 01:58

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.

Jun 18 2009 01:11

Thanks soooooo much this worked for me (using Wordpress 2.8)

DeeDee

Jun 18 2009 01:12

I meant that the two plugins and the instructions from JQuintana worked.

Jul 26 2009 19:32

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.

Jul 27 2009 17:16

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?

Jul 30 2009 00:56

This works for me without editing .htaccess file

Go to Permalink Settings: Custom Structure

/%category%/%postname%/

and edit category base to ./

Jul 30 2009 06:33

yes, via WP-ADMIN and permalinks, you can also do it.

cheers

Jul 30 2009 20:19

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

Aug 20 2009 16:01

Thanks Jean-Baptiste, Angelica and yuryrush.

Editing the htaccess together with ./ as category base in permalinks-settings did the trick.
Thanks.

Aug 21 2009 12:09

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/

Aug 28 2009 04:06

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

Sep 10 2009 23:41

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.

Sep 17 2009 08:57

Put it at the beginning of the .htaccess file. It should work.
Great tip..will really help optimize my site. Thanks

Oct 07 2009 06:04

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.

Oct 09 2009 13:48

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…

Nov 02 2009 14:53

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.

Nov 02 2009 20:48

How can I remove /author/ from my Wordpress URL?
can anyone help?

Nov 21 2009 18:22

Anyone didn’t notice that if someone visit the page of a category… a 404 error code will appear?

Dec 28 2009 19:12

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%.

Dec 29 2009 00:23

This is the better. Highly recommended !

http://wordpress.org/extend/plugins/wp-no-category-base/

Jan 07 2010 15:48

I test this one: wordpress.org/extend/plugins/wp-no-category-base/

and it works even without this Redirection plugin.

Cheers

Jan 19 2010 00:00

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.

Jan 22 2010 17:50

Alright, cool. I’m going to try the plugin first.

Jan 25 2010 10:56

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

Jan 31 2010 03:07

Works great thanks

Trackbacks:

Leave a Comment

* Name, Email, Comment are Required