[wp-trac] Re: [WordPress Trac] #8823: Canonical redirects when it should not

WordPress Trac wp-trac at lists.automattic.com
Wed Jan 21 19:31:34 GMT 2009


#8823: Canonical redirects when it should not
--------------------------+-------------------------------------------------
 Reporter:  andy          |        Owner:  markjaquith
     Type:  defect (bug)  |       Status:  new        
 Priority:  normal        |    Milestone:  2.7.1      
Component:  Canonical     |      Version:  2.7        
 Severity:  normal        |   Resolution:             
 Keywords:                |  
--------------------------+-------------------------------------------------
Changes (by jeremyclarke):

 * cc: jeremyclarke (added)

Comment:

 filosofo: That just doesn't work for me either and I have a permalink
 structure like the one you named. There is no accesible way to get the
 date in with a category name.

 Just to be clear, the goal is to show only posts from that category and
 that time period, not to get to a specific post as your example implies.
 Changing the post permalink structure seems to have no effect for me, and
 if I add stuff like that in the 'category base' option it just creates
 broken links with the replacements (%year%) still inside.

 It's not a simple problem but its an important one to face, as cat+month
 is pretty obvious as a need.

 @andy and @akhost: My solution for this was to disable redirect_canonical
 selectively. In my plugin code I check the query variables, and if 'm'
 (month) is present then I disable redirect canonical, otherwise I leave it
 alone. This lets the rest of the SEO benefits work without stopping the
 month archives from working.


 {{{
 // --------------------------------------------
 // Filter redirect_canonical to disable it for ?m=
 // --------------------------------------------
 //
 // End redirection any time there is a $m value in the url
 // Passing FALSE to redirect_canonical filter ends redirection
 // Needed for ?cat=x&m=y style urls to work. Otherwise you are
 // forwarded to category without month.

 // DISABLED: this turns off canonical redirectoin completely, which is
 overkill. see above.
 // remove_filter('template_redirect', 'redirect_canonical');

 function gv_redirect_canonical($redirect_url) {
         global $wp_query, $wp;
         if ((int) $_GET['m']) return FALSE;
         return $redirect_url;
 } //gv_redirect_canonical()

 add_filter('redirect_canonical', 'gv_redirect_canonical');
 }}}

-- 
Ticket URL: <http://trac.wordpress.org/ticket/8823#comment:6>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list