admin管理员组

文章数量:1426839

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.

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.

Share Improve this question asked May 15, 2019 at 7:34 user167290user167290 2
  • Yes you have to flush rules after rewriting you could update the permalinks via admin panel – siddhesh Commented May 15, 2019 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 Commented May 15, 2019 at 8:28
Add a comment  | 

1 Answer 1

Reset to default 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.

本文标签: url rewritingRewrite rules in multisite