I’m trying to force return 404 if url matches "feed"
: http://example.com/wordpress/?feed=rss2
I added RedirectMatch ^(.*)feed(.*)$ [R=404]
to .htacess but it doesn’t return any 404 error.
For WordPress in functions.php I can use next code:
function fb_disable_feed() {
include( get_query_template( '404' ) );
header('HTTP/1.0 404 Not Found');
exit;
}
add_action('do_feed', 'fb_disable_feed', 1);
add_action('do_feed_rdf', 'fb_disable_feed', 1);
add_action('do_feed_rss', 'fb_disable_feed', 1);
add_action('do_feed_rss2', 'fb_disable_feed', 1);
add_action('do_feed_atom', 'fb_disable_feed', 1);
But it redirects http://example.com/wordpress/?feed=rss2
(301) to http://example.com/wordpress/feed
and only then it returns 404 error.
I need that http://example.com/wordpress/?feed=rss2
would return 404 error & not redirect to http://example.com/wordpress/feed
Instead of using WP PHP code you can do this via mod_rewrite rule.
Place this rule as first rule in your main WP .htaccess: