Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return 404 for any Wordpress's feed/rss

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

like image 447
user25 Avatar asked Feb 24 '26 08:02

user25


1 Answers

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:

RewriteEngine On

RewriteCond %{THE_REQUEST} feed [NC]
RewriteRule ^ - [L,R=404]
like image 95
anubhava Avatar answered Feb 26 '26 23:02

anubhava