Rewrite rules redirecting using Rewrite API

[ad_1]

Hi there, quick question for you…

I’m using the Rewrite API for the first time, but the problem is the URLs aren’t rewriting – they’re instead redirecting.

I’ve only played around with a pretty standard example I found on a few posts on the topic – see below:

add\_action(‘init’, ‘rewrite\_rule\_example’);

function rewrite\_rule\_example(){

add\_rewrite\_rule(‘\^post-by-slug/(.\*)/?’. ‘index.php?name=$matches\[1\]’, ‘top’);

flush\_rewrite\_rules();

}

Is there something I’m missing here? Appreciate any help!

Thanks!

[ad_2]
1 Comment
  1. You have a typo:

    `add_rewrite_rule(‘^post-by-slug/(.*)/?’. ‘index.php?name=$matches[1]’, ‘top’);`

    should be:

    `add_rewrite_rule(‘^post-by-slug/(.*)/?’, ‘index.php?name=$matches[1]’, ‘top’);`

    The period for a comma. Gets you every time.

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer