admin管理员组文章数量:1431994
I have a permalink issue. For your information, there are a few different categories within a website and there are many posts in a single category.
My permalink setting is:
Custom Stucture: /%category%/%postname%/
Category Base: .
After this setting saved, my url will be
www.mydomain/category-slug-name/
instead of
www.mydomain/category/category-slug-name/
I have set the Blog pages show at most: 8 posts under the Setting > Reading. The pagination will appear when there are more than 8 posts in a category page.
I clicked on "page 2", and noticed that www.mydomain/category-slug-name/page/2/
brought me to 404 error page.
Originally, the url of any category "page2" is www.mydomain/category/category-slug-name/page/2/
, it works fine if there is "category" within the url as original url. Or else, it would be 404 error page.
My main concern is, I don't want the category appear in the url. But i want the slug name of category appear in url when i viewing the selected post. And "/page/2/" and the rest will work fine.
Hopefully that this issue is not going to be resolved with recommended plugins. Because, I don't want the website to be too heavy.
Any suggestions?
I have a permalink issue. For your information, there are a few different categories within a website and there are many posts in a single category.
My permalink setting is:
Custom Stucture: /%category%/%postname%/
Category Base: .
After this setting saved, my url will be
www.mydomain/category-slug-name/
instead of
www.mydomain/category/category-slug-name/
I have set the Blog pages show at most: 8 posts under the Setting > Reading. The pagination will appear when there are more than 8 posts in a category page.
I clicked on "page 2", and noticed that www.mydomain/category-slug-name/page/2/
brought me to 404 error page.
Originally, the url of any category "page2" is www.mydomain/category/category-slug-name/page/2/
, it works fine if there is "category" within the url as original url. Or else, it would be 404 error page.
My main concern is, I don't want the category appear in the url. But i want the slug name of category appear in url when i viewing the selected post. And "/page/2/" and the rest will work fine.
Hopefully that this issue is not going to be resolved with recommended plugins. Because, I don't want the website to be too heavy.
Any suggestions?
Share Improve this question edited Dec 22, 2014 at 7:34 Pieter Goosen 55.4k23 gold badges116 silver badges210 bronze badges asked Dec 22, 2014 at 7:25 JornesJornes 7535 gold badges12 silver badges31 bronze badges5 Answers
Reset to default 17That is totally normal behaviour. If you want to remove category base you will need to write some custom rewrite rules, not simple rules I must say. From my point of view, removing category base requires a extra job in each request that is worthless because it doesn't provide any advantage for SEO or for better site navigation. Some popular plugins, like WordPres SEO by Yoast, had this option in the past and removed it some time ago. But this is just an opinion.
Configure category base to .
(dot), put this code in the functions.php of your theme, or better in a plugin, and flush the rewrite rules (code from this post in Daily Web Kit):
add_filter( 'category_rewrite_rules', 'vipx_filter_category_rewrite_rules' );
function vipx_filter_category_rewrite_rules( $rules ) {
$categories = get_categories( array( 'hide_empty' => false ) );
if ( is_array( $categories ) && ! empty( $categories ) ) {
$slugs = array();
foreach ( $categories as $category ) {
if ( is_object( $category ) && ! is_wp_error( $category ) ) {
if ( 0 == $category->category_parent ) {
$slugs[] = $category->slug;
} else {
$slugs[] = trim( get_category_parents( $category->term_id, false, '/', true ), '/' );
}
}
}
if ( ! empty( $slugs ) ) {
$rules = array();
foreach ( $slugs as $slug ) {
$rules[ '(' . $slug . ')/feed/(feed|rdf|rss|rss2|atom)?/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$rules[ '(' . $slug . ')/(feed|rdf|rss|rss2|atom)/?$' ] = 'index.php?category_name=$matches[1]&feed=$matches[2]';
$rules[ '(' . $slug . ')(/page/(\d)+/?)?$' ] = 'index.php?category_name=$matches[1]&paged=$matches[3]';
}
}
}
return $rules;
}
This Worked for me, Add this function in your functions.php page in wordpress and this function will change your like:
Previous: http://www.example/advice/category/category_name/page/3/
To: http://www.example/advice/category_name/page/3/
function remove_category_slug_url($query_string){
if ($query_string['name'] == 'page' && isset($query_string['page'])) {
unset($query_string['name']);
list($delim, $page_index) = explode('/', $query_string['page']);
$query_string['paged'] = $page_index;
}
return $query_string;
}
add_filter('request', 'remove_category_slug_url');
function
remove_category_slug_url($query_string){
if ($query_string['name'] == 'page' && isset($query_string['page'])) {
unset($query_string['name']);
list($delim, $page_index) = split('/', $query_string['page']);
$query_string['paged'] = $page_index;
}
return $query_string;
}
add_filter('request', 'remove_category_slug_url');
This Worked for me, Add this function code in your functions.php in wordpress
note: go to settings->permalinks and click on "save". This will make that WordPress rebuild the rewrite rules taking in account the new ones
For anyone else having this problem, with the redirects on paginated pages, the following worked for me:
In your permalinks, change: /%category%/%postname%/
to
/%category%/%postname%
Notice the removal of the ending forward slash "/".
Rob
This worked for me.
function remove_page_from_query_string($query_string){
if ($query_string['name'] == 'page' && isset($query_string['page'])) {
unset($query_string['name']);
// 'page' in the query_string looks like '/2', so i'm spliting it out
list($delim, $page_index) = split('/', $query_string['page']);
$query_string['paged'] = $page_index;
}
return $query_string;
}
add_filter('request', 'remove_page_from_query_string');
本文标签: categoriesCustom permalink structure leads to be 404 on pagination
版权声明:本文标题:categories - Custom permalink structure leads to be 404 on pagination 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745454686a2659046.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论