1

I'm attempting to add a rewrite so feeds for pages that list specific post categories work.

eg. /mining-civil-engineering/newsroom/feed/ would point to index.php?cat=21,22&feed=rss2

These rewrites are added programatically based on a template type, so they don't have to be added manually. I'm using add_rewrite_rule.

Unfortunately, $wp_rewrite still seems to only match to the rule designating page comments (.?.+?)/(feed|rdf|rss|rss2|atom)/?$ outputting to pagename=mining-civil-engineering%2Fnews-events&feed=feed.

I tried using $wp_rewrite->non_wp_rules so my .htaccess now looks like

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^national-security/events/feed/ /index.php?cat=10&feed=rss2 [QSA,L]
RewriteRule ^mining-civil-engineering/news-events/feed/ /index.php?cat=21,22&feed=rss2 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Unfortunately it still seems to only match on the previous query. I commented out in my htaccess lines until it knew it was only working with the rewrite I wanted, but the body still returned the comments feed, and my debugging showing it was matching on the feed url. I did flush with both $wp_rewrite->flush_rules( true ); and re-saving permalinks in the admin.

Any ideas on what I'm doing wrong? I'm utterly lost.

Thanks!!

  • Manually rewriting URLs in .htaccess (to override WordPress's default behaviour) is often problematic because WordPress still sees the original URL on the request (ie. /national-security/events/feed/ - the value of $_SERVER['REQUEST_URI']) and routes the request according to that. (?) – MrWhite Mar 5 '18 at 15:50
  • @MrWhite - so I have to make it work with add_rewrite_rule() but to do that I'd have to remove the rewrite in the list that it's catching on perhaps? – Thomas Huxley Mar 6 '18 at 6:44
-1

The solution was to modify my regex slightly in my add_rewrite_rule.

The rule was ^/mining-civil-engineering/news-events/feed/ and now reads ^/mining-civil-engineering/news-events/(feed|rss2)/?$

  • What exactly did you have to change? The regex in your example looks like it would match? Thanks for your feedback. – MrWhite Mar 6 '18 at 7:34
  • This answer will not help anyone with the same problem. Please be more specific. – fuxia Mar 6 '18 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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