WordPress.org

Make WordPress Core

Changeset 37726


Ignore:
Timestamp:
06/16/2016 02:58:28 PM (4 years ago)
Author:
rachelbaker
Message:

REST API: Include X-Robots-Tag: noindex header in REST API responses to prevent endpoints from being indexed by search engines.

Prevent duplicate content issues with search engines and REST API endpoint response data.

Fixes #36390.
Props m_uysl for the initial patch.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/class-wp-rest-server.php

    r37674 r37726  
    227227        $content_type = isset( $_GET['_jsonp'] ) ? 'application/javascript' : 'application/json';
    228228        $this->send_header( 'Content-Type', $content_type . '; charset=' . get_option( 'blog_charset' ) );
     229        $this->send_header( 'X-Robots-Tag', 'noindex' );
    229230
    230231        /*
  • trunk/tests/phpunit/tests/rest-api/rest-server.php

    r37163 r37726  
    718718    }
    719719
     720    public function test_x_robot_tag_header_on_requests() {
     721        $request = new WP_REST_Request( 'GET', '/', array() );
     722
     723        $result = $this->server->serve_request('/');
     724        $headers = $this->server->sent_headers;
     725
     726        $this->assertEquals( 'noindex', $headers['X-Robots-Tag'] );
     727    }
     728
    720729    public function test_nocache_headers_on_authenticated_requests() {
    721730        $editor = self::factory()->user->create( array( 'role' => 'editor' ) );
Note: See TracChangeset for help on using the changeset viewer.