• Hi I want to write a plugin, when custom post types are used, it requires having mod_rewrite changes, WP offers API for that purpose, but I can’t understand how they work, or what I do wrong. I have a rule in .htaccess which actually does a job RewriteRule ^news/((?!\d{1,3}/?$).+)/?$ /?pt-news=$1 [L,QSA,NC] I want to move it to WP API and add to functions.php that code:
    add_rewrite_rule("^news/((?!\d{1,3}/?$).+)/?$", '/?pt-news=$1 [L,QSA,NC]', 'top');

    It has not any affect on WP behavior, what do I do wrong?

Viewing 2 replies - 1 through 2 (of 2 total)
  • I think this code will work you have missed to wrap inside a function and call it

    function custom_post_rewrite() {
      add_rewrite_rule('^news/((?!\d{1,3}/?$).+)/?$', '/?pt-news=$1 [L,QSA,NC]', 'top');
    }
    add_action('init', 'custom_post_rewrite');
    Thread Starter nick222

    (@nick222)

    Thank for idea, but I did not. My mistake was confusing apache mod_rewrite rules with WP rewrite rules which are based on php regular expressions and internal logic.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘add_rewrite_rule does not work when .htaccess works’ is closed to new replies.