[wp-trac] [WordPress Trac] #51725: Canonical redirect and user_trailingslashit()

WordPress Trac noreply at wordpress.org
Wed Apr 28 05:21:27 UTC 2021


#51725: Canonical redirect and user_trailingslashit()
----------------------------------------+------------------------------
 Reporter:  mbis                        |       Owner:  (none)
     Type:  defect (bug)                |      Status:  new
 Priority:  normal                      |   Milestone:  Awaiting Review
Component:  Canonical                   |     Version:  5.5.2
 Severity:  trivial                     |  Resolution:
 Keywords:  has-patch needs-unit-tests  |     Focuses:
----------------------------------------+------------------------------

Comment (by bobz):

 This was the fix in my case, I'm using relative permalinks without
 trailing slash.

 {{{#!php
 <?php
 add_filter( 'redirect_canonical', function( $redirect_url, $requested_url
 ) {

     $redirect  = parse_url( $redirect_url );
     $requested = parse_url( $requested_url );

     // Prevent redirect to exact same page
     if ( strtolower($redirect['path']) == strtolower($requested['path']) )
     {
         return false;
     }

 }, 101, 2 );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51725#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list