WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Custom Rewrite Rules stopped working with 3.1

[Resolved] Custom Rewrite Rules stopped working with 3.1

  • I’ve been using in our site for a while now custom rewrites that allows us to “filter” content. e.g.: http://www.domain.com/category/filter-id/

    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)
  • http://wordpress.org/extend/plugins/hotfix/

    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, http://www.domain.com/category/?ss_filter=filter&filter_id=ID 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!

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

    @ipstenu

    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:
    http://wordpress.org/support/topic/custom-rewrite-rules-stopped-working-with-31

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

    Code:
    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, http://codex.wordpress.org/Function_Reference/WP_Rewrite

    hope this helps!

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

    add_filter('wp_loaded','flushRules');
    
        // Remember to flush_rules() when adding rules
        function flushRules(){
                global $wp_rewrite;
                $wp_rewrite->flush_rules();
        }

    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 ‘[Resolved] Custom Rewrite Rules stopped working with 3.1’ is closed to new replies.
Skip to toolbar