WordPress.org

Ready to get started?Download WordPress

Forums

How to remove "/category" from the category URL? (11 posts)

  1. erick_paper
    Member
    Posted 6 years ago #

    Hi. In my theme, the category links show up as:

    http://domain.com/wp/category/mycat

    For backward compatibility of URLs, I would like to remove the bold word in that URL ("/category") because wordpress in fact works if I remove that. Just the name of the category ("mycat" in my example) is fine to bring up the category archive without any problem.

    Thanks for any tips!

  2. t3ch33
    Member
    Posted 6 years ago #

    use a rewrite

  3. erick_paper
    Member
    Posted 6 years ago #

    I think it's not an issue of doing a rewrite, because the theme itself writes the URLs. I want to change how the category URL is linked from within the theme while calling wp_list_categories.

    So the "/category" is autmatically added by WP!

    I checked the options for this function:
    http://codex.wordpress.org/Template_Tags/wp_list_categories

    But there seems to be none that allows me to personalize the word used for "category".

  4. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    You can change the word to anything you like on the Options->Permalink page, but you cannot remove it. The identifier is needed to signal that you are asking for a category.

    As for why it works without it, let me guess: Your Custom Permalink string starts with /%category% , right? If it didn't, then leaving it out would not work.

    Removing it entirely would require a large rewrite of the internal rewrite and query system. Using category in the custom permalinks is a bit of a hack anyway, since there is not a one-to-one correspondence between categories and posts; posts can have more than one category.

  5. erick_paper
    Member
    Posted 6 years ago #

    Thanks for a very informative post!

    I found the "category base" works for me.

  6. KingRosales
    Member
    Posted 6 years ago #

    I have a site that automatically lists the categories prefixed with "domain-name/category/directory-name".

    If you create a navigation menu and simply hard-code "domain-name/directory-name", I've discovered that it works just the same; The hard-coded urls also get indexed like every other page on your website or blog.

    - I've used this technique on my sites that I want to ensure the url and directory can easily be memorized.

    However, in most cases, if you dont have a SEO keyword in your domain name, I recommend using the "category" structure and replace that with an industry keyword.

  7. wdm
    Member
    Posted 6 years ago #

    Using "/." (without quotes) as the category base should work

  8. wdm
    Member
    Posted 6 years ago #

    Hmm... it did work, but not anymore.
    Seems not to work all the time, anyone know why?

  9. Joshua Goodwin
    Member
    Posted 6 years ago #

    Use the top level categories plugin, if you want to remove the prefix altogether.

  10. design_dolphin
    Member
    Posted 5 years ago #

    Alfa code

    Important! Not for live website use unless you know what you are doing. For development use until testing has been completed and reviewed by a community of peers. If implemented (incorrectly) it can cause site errors. Use at your own risk.

    <IfModule mod_rewrite.c>
    Options +FollowSymLinks
        RewriteEngine On
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php/$1 [L]
       RewriteRule category_base/(.*) http://yourdomain.com/$1 [R=301,NC,L]
      	</IfModule>

    Ran into the similar problem of wanting the category base word out of the url.

    Am testing the code above in the latest stable version of 2.7. 'category_base' is the category base name from the permalinks settings menu.

    Haven't run into any problems with it, but haven't tested it extensively enough to say without a shadow of a doubt it will work all the time and safely. So far the urls of the site that I have tested index.php, categories, single pages as well as comments appear to work.

    In the permalink settings in the settings menu the 'custom structure' is selected and set to:

    /%category%/%postname%.html
  11. ogonkov
    Member
    Posted 5 years ago #

    I will put "." (dot) as a category base, and it's will nice shown now as /./category/. But, is there any chance to remove this dot? Without .htaccess. May be there are some hidden features in WP?

Topic Closed

This topic has been closed to new replies.

About this Topic