Rewrite Rules to blog/%postname%/
-
We have a site that requires all blog posts to be blog/%postname%/ and have the below function in the functions file to rewrite them as such. However, while this works for the permalink structure, it is creating pagination issues to where blog/page/2 returns a 404. I am not great with permalink rewrites, but can someone see the issue in the code? (This was done by a freelancer):
add_action( 'generate_rewrite_rules', 'add_blog_rewrites' ); function add_blog_rewrites( $wp_rewrite ) { $wp_rewrite->rules = array( 'blog/([^/]+)/?$' => 'index.php?name=$matches[1]', 'blog/[^/]+/attachment/([^/]+)/?$' => 'index.php?attachment=$matches[1]', 'blog/[^/]+/attachment/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', 'blog/[^/]+/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/attachment/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]', 'blog/([^/]+)/trackback/?$' => 'index.php?name=$matches[1]&tb=1', 'blog/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?name=$matches[1]&feed=$matches[2]', 'blog/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?name=$matches[1]&feed=$matches[2]', 'blog/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?name=$matches[1]&paged=$matches[2]', 'blog/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?name=$matches[1]&cpage=$matches[2]', 'blog/([^/]+)(/[0-9]+)?/?$' => 'index.php?name=$matches[1]&page=$matches[2]', 'blog/[^/]+/([^/]+)/?$' => 'index.php?attachment=$matches[1]', 'blog/[^/]+/([^/]+)/trackback/?$' => 'index.php?attachment=$matches[1]&tb=1', 'blog/[^/]+/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/([^/]+)/(feed|rdf|rss|rss2|atom)/?$' => 'index.php?attachment=$matches[1]&feed=$matches[2]', 'blog/[^/]+/([^/]+)/comment-page-([0-9]{1,})/?$' => 'index.php?attachment=$matches[1]&cpage=$matches[2]', ) + $wp_rewrite->rules; }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Rewrite Rules to blog/%postname%/’ is closed to new replies.