After searching here and there, probably I found solution. (Don’t know if I am doing wrong in WP terminology!)
Page was redirecting from .../page5
to .../page/5
, because of redirect_canonical
function resides in WordPress core.
So I further searched for altering it by hook
.
Few people were saying remove redirect_canonical
filter by adding this in code: remove_filter('template_redirect','redirect_canonical');
.
But, after checking some other answers, I think I have to correct only my case, as removing whole redirect_canonical
filter cause trouble in other part of WordPress.
Here is my final code which was added in my theme’s functions.php
function remove_page_number_permalink_redirect( $redirect_url )
{
if (is_paged() && get_query_var('paged') > 0) {
return false;
}
return $redirect_url;
}
add_filter( 'redirect_canonical', 'remove_page_number_permalink_redirect' );