WordPress.org

Make WordPress Core

Ticket #4554: canonical_trailing_slash.diff

File canonical_trailing_slash.diff, 1.0 KB (added by ryan, 8 years ago)
  • wp-includes/default-filters.php

     
    183183add_action('init', 'smilies_init', 5); 
    184184add_action( 'plugins_loaded', 'wp_maybe_load_widgets', 0 ); 
    185185add_action( 'shutdown', 'wp_ob_end_flush_all', 1); 
     186add_action( 'parse_request', 'canonical_trailing_slash'); 
    186187 
    187188?> 
     189 No newline at end of file 
  • wp-includes/functions.php

     
    13171317        while ( @ob_end_flush() ); 
    13181318} 
    13191319 
     1320function canonical_trailing_slash( $request ) { 
     1321        if ( ! $request->did_permalink ) 
     1322                return; 
     1323 
     1324        if ( !empty($request->query_vars['error']) ) 
     1325                return; 
     1326 
     1327        $req = $_SERVER['REQUEST_URI']; 
     1328        $req = user_trailingslashit($req); 
     1329        if ( $req == $_SERVER['REQUEST_URI'] ) 
     1330                return; 
     1331 
     1332        wp_redirect($req, '301'); 
     1333        exit; 
     1334} 
     1335 
    13201336?>