WordPress.org

Ready to get started?Download WordPress

Forums

2.0 Rewrite rules question (7 posts)

  1. badrad
    Member
    Posted 8 years ago #

    I'm working on my first WordPress site, so thanks in advance for any help.

    I wanna forward my feed traffic to feedburner, but use the default feed URL so I can always take away feedburner without causing people to have to update their feed burners.

    So, I put this in my htaccess above the wordpress rules:

    RewriteRule ^feed/ http://feeds.feedburner.com/XYZ [NC]

    In wordpress 1.5, this worked. In wordpress 2.0, it does not. I noticed WordPress 2.0 has a new way of making rewrite rules, showing only one rule rather then the usual many. I found $use_verbose_rules in classes.php. Setting it to true brought back the old rewrite behavior, and also allowed my feedburner redirects to start working.

    So, my question is, is their any reason I shouldn't use the verbose rules? Are they slower, or depreciated, or likely to break? Or was the change to simplify the rules or increase compatability?

    Or is there a way I can get the forward to work without using verbose rules?

  2. Austin Matzko
    Member
    Posted 8 years ago #

    So, my question is, is their any reason I shouldn't use the verbose rules?

    The advantage is that you don't have to worry about messing with the .htaccess file: WP handles all of that internally.

    Or is there a way I can get the forward to work without using verbose rules?

    You can add the rule using a filter. Creating a plugin with something like the following function and filter should do it:

    function feed_redirect($rules) {
    $rules['feed/'] = 'http://feeds.feedburner.com/XYZ';
    return $rules;
    }
    add_filter('rewrite_rules_array', 'feed_redirect');

  3. badrad
    Member
    Posted 8 years ago #

    Thanks for the tips on writing the plugin filosofo, I really appreciate it.

    I wrote it like you suggested, and it was not working. I turned verbose rules back on to see how WordPress was applying the rules my plugin specified, and I can see it is not working for the following reasons:

    1. The rewrite rules I specify in the plugin are appended to the WordPress rules, they come after. Since rewrite rules are executed in order, and since WordPress has its own internal feed rewriting, this means my rules fail to work. Is their away to have the plugin prepend its rules, to make them so they come first?

    2. WordPress is putting a beginning slash that I have not specified. For example, the first rule comes out like this:
    RewriteRule ^feed/ /http://feeds.feedburner.com/XYZ [QSA,L]

    You can see the slash before the http:. This also causes it to fail.

    These two things are stopping me from being able to use a plugin to modify the rewrite rules, rather then having to force wordpress to use verbose rules and then add my own by hand. While I have no problem doing that, I'd rather modify as few external wordpress files as possible to make upgrading and what have you easy.

    Can anyone think of a solution to these 2 issues?

  4. doryphores
    Member
    Posted 8 years ago #

    badrad: have you found a solution to your problem? I have the same situation with one of my plugins.

  5. Austin Matzko
    Member
    Posted 8 years ago #

    The rewrite rules I specify in the plugin are appended to the WordPress rules, they come after. Since rewrite rules are executed in order, and since WordPress has its own internal feed rewriting, this means my rules fail to work. Is their away to have the plugin prepend its rules, to make them so they come first?

    If you want to prepend your rule using a function like the one I suggested above, instead of this line
    $rules['feed/'] = 'http://feeds.feedburner.com/XYZ';
    do something like this:
    $newrules['feed/'] = 'http://feeds.feedburner.com/XYZ';
    $rules = array_merge($newrules,$rules);

    I don't know why WordPress adds a beginning slash.

  6. alif
    Member
    Posted 8 years ago #

    Since inserting custom rules through the rewrite rules filters (for example root_rewrite_rules) works only when in verbose rewrite rules mode, and causing the full rules to be written to .htaccess as indicated in the first post in this thread.

    so, instead of editing classes.php, I tried adding $wp_rewrite->use_verbose_rules = true; to my-hacks.php but it doesn't seem to have an effect.

    Am I missing something?

    I'm considering writing a plug-in to fine tune rewrite rules from within WP. This is important to people who migrate to WP and who want to add rules to map an older system's permalinks.

  7. alif
    Member
    Posted 8 years ago #

    Also, is there a way to append flags to rewrite rules inserted through filters?

    The code in classes.php appends "[QSA,L]" to all rules while they are being written to .htaccess.

Topic Closed

This topic has been closed to new replies.

About this Topic