How to make wordpress category's URL with slash at the end and without it in post's url. Like this:
"mysite.com/mycategory/" "mysite.com/mycategory/mypost"
The problem is that by default, you can either do everything with a slash or all without a slash. ('category' prefix already removed via htaccess).
There are two good solutions for this:
The WP_Rewrite class has a var named
$use_trailing_slashesthat is set dynamically based upon whether or not your custom permalink structure ends in a '/'.This means that all WP generated links (the_permalink, category_link, the_permalink_rss, etc.) will not end in a '/'. So for category pages WP will show '/category/category' instead of '/category/category/'.
You can solve it by either using a filter or modifying your .htaccess or both:
Sample user_trailingslashit Filter
The user_trailingslashit function applies the 'user_trailingslashit' filter to the result prior to returning it. It provides the url and the type of url to the filter.
So to hook into this and add a trailing slash to all urls other than single posts add this code to a plugin file or your functions.php theme file.
Htaccess RedirectMatch
You can setup an .htaccess redirect to force category urls to always use a trailing slash like this:
Source of information: https://www.askapache.com/wordpress/adding-trailing-permalinks/
For any further questions consult the codex:
https://codex.wordpress.org/wp_rewrite
https://codex.wordpress.org/Using_Permalinks