WordPress Permalinks %postname% for RSS2 Feed URL

First of all there isn’t any default way of doing this as far as I’m aware.

If you use the ‘Rewrite rule inspector plugin‘ you’ll see that there isn’t any default rule that combines the category, the date and the feed as parameters.

An example date rule is

([0-9]{4})/([0-9]{1,2})/?$  index.php?year=$matches[1]&monthnum=$matches[2]

and an example category rule is

category/(.+?)/?$   index.php?category_name=$matches[1]

and an example feed rule is

feed/(feed|rdf|rss|rss2|atom)/?$    index.php?&feed=$matches[1]

What you want to do is combine these three rules and create some new rules available to wordpress.

You can do this by adding the below to your functions.php

function rewrite_rules() {
    add_rewrite_rule(
        '([0-9]{4})/([0-9]{1,2})/category/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$',
        'index.php?year=$matches[1]&monthnum=$matches[2]&category_name=$matches[3]&feed=$matches[4]',
        'top'
    ); // /2012/01/category/life-the-universe-and-everything/feed/atom
    add_rewrite_rule(
        '([0-9]{4})/([0-9]{1,2})/category/(.+?)/feed/?$',
        'index.php?year=$matches[1]&monthnum=$matches[2]&category_name=$matches[3]&feed=feed',
        'top'
    ); // /2012/01/category/life-the-universe-and-everything/feed/
    add_rewrite_rule(
        '([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/category/(.+?)/?$',
        'index.php?year=$matches[1]&monthnum=$matches[2]&daynum=$matches[3]&category_name=$matches[4]',
        'top'
    ); // /2012/01/15/category/life-the-universe-and-everything/
    add_rewrite_rule(
        '([0-9]{4})/([0-9]{1,2})/category/(.+?)/?$',
        'index.php?year=$matches[1]&monthnum=$matches[2]&category_name=$matches[3]',
        'top'
    ); // /2012/01/category/life-the-universe-and-everything/
}
add_action( 'init', 'rewrite_rules' );

Hope that answers your question, any problems let me know.

Leave a Comment