I know queries about rewrite rules not working correctly are very common, but in my case I am actually unable to get rules to create in the first place. I need to create a plugin that will be loaded into a number of sites and provide some common functionality to each site. One of those functions it will provide is to create a rewrite rule common to those sites. At this point, I have whittled down the test example to the following:

Debian server running apache 2.4.x, php 5.6.3x, wordpress 4.9.4 using mysql database. The wordpress install is a clean unzipped copy of the source with no plugins enabled. It's just been brought to the point of finishing the initial setup. The apache vhost is set up to AllowOverrides All, but the issue here isn't even with .htaccess writing because I do see wordpress updating the .htaccess file to show the following (but never putting rules in it):

# BEGIN WordPress

# END WordPress

I created a plugin in wp-content/plugins/test-plugin/test-plugin.php.

After gradually pulling away pieces of code, I have it running only this code in the test plugin file now:

function test_rules()
    echo "test"; // Just to see that the function is being called
    global $wp_rewrite;
add_action('init', 'test_rules');

Obviously this is stupid code simply to try to isolate where the rewrite API is failing. When I load the index of the site, the code is running because I do see the "test" output as well as the var_dump() output. In all cases, however, the var_dump() output is an array with no values in it. Any variations of ordering the flush_rules (or not using it, etc) seems to have no effect.

I am also looking in the database and doing SELECT * FROM wp_options WHERE option_name = 'rewrite_rules'. The row exists but the value of the option is never being populated.

I had initially tried to set this up on a site with existing code but now I am using a fresh naked install with only the above plugin included (and yes, it's active) and I am just not getting these rules. Can someone tell me what I am missing here?


  • 1
    Do you have Pretty Permalinks enabled? The only case where the rewrites option will be empty is if the "plain" option is selected (pretty permalinks disabled). Also note that the rule you are adding is an internal rule, and will never show up in the .htaccess file, as internal rules are parsed in PHP after the request is handed over to WordPress.
    – Milo
    Commented Mar 14, 2018 at 3:36
  • Hi Milo, that was the issue. Thanks. Nothing I'd read on WP_Rewrite usage had discussed the dependence on the permalink setting in admin previously, and unfortunately I have little applied experience previously with WP, but it's going to be coming fast and strong now. I believed it was expected that there would be no .htaccess writes for this rule but I still wanted to cover all the bases of my tests to have as few potential response questions. :)
    – JRLEH
    Commented Mar 14, 2018 at 14:55

1 Answer 1


Correct solution provided by Milo in comment above. Pretty permalinks were set to plain in the admin interface and this evidently causes the WP_Rewrite to silently do nothing. I'm posting the answer here so I can mark something as correct/complete so this shows as answered. Am I doing it wrong?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.