0

I've been trying to set up different rewrite rules on my multisite installation, but as of now, nothing is working. Even the simple

add_rewrite_rule('^welcome$', 'index.php?p=1', 'top');

isn't working.

Is there anything to do when setting up rewrite rules using the Rewrite API that needs to be done that isn't explicitity defined in the codex?

This problem led me to wonder: are rewrite rules written using the API supposed to be written in .htaccess or not?

Thank you in advance.

PS. If I'm duplicating, I am sorry, but I haven't been able to find a well written answer yet.

  • Yes you have to flush rules after rewriting you could update the permalinks via admin panel – siddhesh May 15 at 8:25
  • I am flushing them. I've tried these three ways: resaving the permalinks in the admin panel, global $wp_rewrite; $wp_rewrite->init(); $wp_rewrite->flush_rules(); and flush_rewrite_rules();. – user167290 May 15 at 8:28
0

Found the answers:

  1. There is nothing to do when using the Rewrite API that isn't written in the Codex.
  2. Rules written using add_rewrite_rule are not added to .htaccess. WP adds them to its database under rewrite_rules in the _options table.

It's important not to forget to:

  • Filter the rewritten permalinks; call the functions on the post_type_link hook and/or the term_link hook depending on the situation.
  • Remove default rules to avoid conflict and call the function/s on the rewrite_rules_array hook.
  • Flush and rewrite the rules using flush_rewrite_rules(); on plugin activation and/or deactivation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy