WordPress permalink pagination not working

Say for example i have created a custom post type. I have implemented pagination for the same.

When i call this url

http://localhost.dm/news/multi-media-gallery/page/2/, it show page not found.

But if i try with

http://localhost.dm/news/multi-media-gallery?page=2,  it work.

Now to make the pagination work with permalink you need to add the following rewrite rule in your theme functions.php

add_action(‘init’, function ()
add_rewrite_rule(‘(.?.+?)/page/?([0-9]{1,})/?$’, ‘index.php?pagename=$matches[1]&paged=$matches[2]’, ‘top’); flush_rewrite_rules();
}, 1000);