【问题标题】:Return 404 for any Wordpress's feed/rss为任何 Wordpress 提要/rss 返回 404
【发布时间】:2015-11-04 03:31:38
【问题描述】:

如果 url 匹配 "feed": http://example.com/wordpress/?feed=rss2

,我正在尝试强制返回 404

我在 .htacess 中添加了 RedirectMatch ^(.*)feed(.*)$ [R=404],但它没有返回任何 404 错误。

对于functions.php中的Wordpress,我可以使用下一个代码:

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);

但它会将http://example.com/wordpress/?feed=rss2 (301) 重定向到http://example.com/wordpress/feed,然后才返回 404 错误。

我需要 http://example.com/wordpress/?feed=rss2 会返回 404 错误而不重定向到 http://example.com/wordpress/feed

【问题讨论】:

    标签: php wordpress apache .htaccess mod-rewrite


    【解决方案1】:

    您可以通过 mod_rewrite 规则来代替使用 WP PHP 代码。

    将此规则作为第一条规则放在您的主 WP .htaccess 中:

    RewriteEngine On
    
    RewriteCond %{THE_REQUEST} feed [NC]
    RewriteRule ^ - [L,R=404]
    

    【讨论】:

      猜你喜欢
      • 2018-10-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-13
      • 1970-01-01
      • 2018-04-20
      • 2011-01-22
      • 2010-12-19
      相关资源
      最近更新 更多