Support » Fixing WordPress » Custom Rewrite Rules stopped working with 3.1

  • Resolved uilhao


    I’ve been using in our site for a while now custom rewrites that allows us to “filter” content. e.g.:

    Things have veen working extremely well until I updated worpdress to 3.1. It seems that all of the custom rewrites for categories do not work now. We have a few filters for some pages and those still work.

    Here is a sample code of what I’m using:

    $newrules[‘(‘.$category_nicename.’)/(‘.$filter_name.’)-(‘.$filter_id.’)/?$’] = ‘index.php?category_name=$matches[1]&ss_filter=$matches[2]&filter_id=$matches[3]’;

    So up until 3.1, everything worked. I am flushing the rules and adding the new variables to the query_var filter as well. See below

    add_filter(‘rewrite_rules_array’,’ss_rewrite_rules_array’); Where I’m adding the new rules
    add_filter(‘query_vars’,’ss_query_vars’); Adding the new vars (ss_filter and filter_id)
    add_filter(‘admin_init’,’ss_flushRules’); Flushing rules when going to admin area.

    I’ve searched around and seems a few more people are having the same issue.

    Anyone with advise is greatly appreciated.

Viewing 10 replies - 1 through 10 (of 10 total)

    Try this plugin. Its kept up to date with whatever bugfixes apply to the currecnt version of WP. There is one relevant to 3.1

    I’m not sure it applies to you, but worth a shot

    @rev. Voodoo

    Thank so much for the reply and the share. Unfortunately this did not fix the issue. Funny thing it does recognize the filter as the url does not break. If I remove the custom rules and do a flush, the url returns a 404 or redirects to a random post, but when I reactivate the custom rules, the page simply redirects itself to the current category, but without the filter. I also hardcoded to the rule to load a different category at index.php?category_name=. So if I was loading category X, I put in the rule to load category Y and it worked fine, it load category Y.

    Loading the url like this, works just fine and I’m able to filter the data correctly, so that parameters and query_vars filter are working, just something weird with the redirect.

    Been trying all kinds of things, but I think I might have to resort to manually adding the rules to my htaccess file… which is a bummer cause wordpress made it really easy to get rewrites done.

    Thanks again!

    Moderator Ipstenu (Mika Epstein)


    🏳️‍🌈 Halfelf Rogue & Plugin Review Team Rep

    Im having a similar problem, trying to rewrite the category permalinks but WP redirects my the the category ignoring my query var :/


    Thank you for the link, it was quite helpful for a few other things but still didn’t solve my rewrite issue.

    Unfortunately I was complied to downgrade to 3.0.5 and wait to see if there will be a fix for this later.

    WordPress rocks and its community even more, so I’m positive this will be addressed soon.

    I haven’t test this yet, but just found this and thought I’d share.

    According to this post:

    By removing the canonical template redirect filter, custom rewrites seem to start working again.

    remove_filter(‘template_redirect’, ‘redirect_canonical’);

    I can confirm that the fix above works fine.

    Just add “remove_filter(‘template_redirect’, ‘redirect_canonical’);” to your functions.php file.

    :(( help me, i haven’t do it yet. uilhao, help me. I added your code line in function.php file, but it don’t work. this is my code:

    remove_filter('template_redirect', 'redirect_canonical');
        /*Custom url rewrite */
        function mechanical_rules( $rewrite_rules ) {
            $new_rules = array(
                '^category/([^/]*)/brand/([^/]*)/.html$' => 'index.php?pagename=products&cate=$matches[1]&br=$matches[2]'
               ,'^brand/([^/]*)/category/([^/]*)/.html$' => 'index.php?pagename=products&br=$matches[1]&cate=$matches[2]'
            $rewrite_rules = $new_rules + $rewrite_rules;
            return $rewrite_rules;
        add_filter('rewrite_rules_array', 'mechanical_rules');
        add_filter('query_vars', 'mechanical_query_vars');
        function mechanical_query_vars($public_query_vars) {
            $public_query_vars[] = 'cate';
            $public_query_vars[] = 'br';
            return $public_query_vars;

    quickly looking, everything seems fine, but you need to flush the rewrite rules.

    There are examples here,

    hope this helps!

    Hi uilhao. I added function.php file the following code:

        // Remember to flush_rules() when adding rules
        function flushRules(){
                global $wp_rewrite;

    But… It hasn’t worked yet.
    I don’t know why :((.
    Do you have other solutions?

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Custom Rewrite Rules stopped working with 3.1’ is closed to new replies.