Opened 13 years ago
Last modified 7 years ago
#19896 new defect (bug)
Non-WP rewrites not saved on a multisite install
Reported by: | johnbillion | Owned by: | |
---|---|---|---|
Milestone: | Awaiting Review | Priority: | normal |
Severity: | normal | Version: | 3.0 |
Component: | Rewrite Rules | Keywords: | needs-patch |
Focuses: | multisite | Cc: |
Description
The following code adds a rewrite rule which is classed as a non-WP rewrite rule because its redirect doesn't begin with index.php
, and is stored in the non_wp_rules
member variable of the WP_Rewrite
class.
function my_rewrite() { add_rewrite_rule( 'login/?$', 'wp-login.php', 'top' ); } add_action( 'init', 'my_rewrite' );
On a single site install, this rewrite rule gets saved directly to the .htaccess file rather than being added to WordPress' internal rewrite array.
On a multisite install, this doesn't happen and the rewrite rule has no effect (probably because once a site is multisite-d WordPress no longer writes to .htaccess). The rule has to be manually added to .htaccess.
Likely introduced in 3.0, reproduced in 3.3 and trunk.
Change History (9)
#3
@
10 years ago
We are having this issue as well, non_wp_rewrites are being added to the non_wp_rules property, but never being added to the wp_rewrite->rules property. This is happening in VIP Quickstart (4.2).
#5
@
10 years ago
Still reproducible. Happens only in multisite since the htaccess file is never written to.
#6
@
9 years ago
I believe I'm encountering this as well. It adds them to the $GLOBALwp_rewrite?->non_wp_rules but never gets saved as a rewrite. This is on a multisite. I've tried adding it very early (1) or very late (20-100) but it never seems to get added. Using the Rewrite Rules plugin to see all the rules as well as Debug Bar to trace the rewrites that are being hit on a given page.
#7
@
9 years ago
Some clarification here though:
<?php add_rewrite_rule( sanitize_title( $region ) . '/([0-9]{4})/([0-9]{1,2})/([^/]+)(?:/([0-9]+))?/?$', 'index.php?year=$matches[1]&monthnum=$matches[2]&name=$matches[3]&page=$matches[4]' , 'top' );
works because the index.php? makes it a wp_rewrite
Without it, it's considered a non wp rule and would be written to .htaccess. However with multisite, that doesn't/can't happen so this doesn't even register as a rewrite rule as it is never written to .htaccess.
<?php add_rewrite_rule( sanitize_title( $region ) . '/?$', '$matches[1]' , 'top' );
Confirmed -- I believe I'm encountering this bug myself. (3.5.1)