How to remove '/category/' on url?

I’m trying to remove ‘/category/’ on url.

Like, to
So, I create this function on clanup.php:

* Redirects category results from /category/%category%/ to /%category%/
function roots_nice_category_redirect() {
  global $wp_rewrite;
  if (!isset($wp_rewrite) || !is_object($wp_rewrite) || !$wp_rewrite->using_permalinks()) {

  $category_base = $wp_rewrite->category_base;
  if (is_category() && !is_admin() && strpos($_SERVER['REQUEST_URI'], "/{$category_base}/") === false) {
    wp_redirect(home_url("/{$category_base}/" . get_query_var('category_name')));
add_action('template_redirect', 'roots_nice_category_redirect');

Almost works, but I’m having a problem with another redirect. When I type, I’m redirected to the post

I believe this redirect is occasioned because the proximity of the name of the post.

Somebody knows how to solve this?

Ps.: The links are not online, they are only for example.

I wouldn’t do this.

If you absolutely must do it, you’ll probably be better off using a plugin. If you can’t use a plugin then you’ll probably want to move your action up in priority and/or disable redirect_canonical.

I see.
I just found out that the Yoast WordPress SEO plugin, wich I already use, has this function and works fine.

Thanks for the help.