[wp-trac] [WordPress Trac] #35012: wp_old_slug_redirect can cause redirect loop

WordPress Trac noreply at wordpress.org
Fri Dec 11 13:08:19 UTC 2015


#35012: wp_old_slug_redirect can cause redirect loop
--------------------------+-----------------------------
 Reporter:  vdwijngaert   |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Canonical     |    Version:  trunk
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 At least one known issue arises since
 https://core.trac.wordpress.org/changeset/34659.

 I noticed this problem when working with the latest version of the WPML
 Multilingual CMS plugin (v3.3.3) in combination with WP 4.4 (same issues
 with trunk version).

 When the translation of a post had the same slug (''example.com/hello-
 world'') as the original post (after duplicating it to the translation)
 and the slug is then updated to reflect the translation (''example.com/fr
 /bonjour-le-monde''), the old slug is saved as ''_wp_old_slug''.

 If we then navigate to ''example.com/hello-world'',
 ''wp_old_slug_redirect()'' tries to do a 301 redirect to ''example.com
 /hello-world'', causing a redirect loop. See this post on the WPML support
 forums: https://wpml.org/forums/topic/hi-several-posts-on-my-website-
 return-a-page-too-many-redirects/.

 I don't know if what WPML does with the slug system (they are supposed to
 be unique) is supposed to be possible, but ''wp_old_slug_redirect()''
 shouldn't be causing a redirect loop nonetheless. I suspect that at this
 very moment it is causing problems with WPML users worldwide, and possibly
 other plugins that do something similar as well.

 In the past this was handled by the ''"is_404()"'' check on line 4733 (now
 line 4989), but that's no longer there. That's why this bug surfaces now.
 Shouldn't WordPress be able to detect or even prevent this redirect loop?

 Right now I have a temporary fix for the websites I'm running. It checks
 whether or not the redirect is to the current permalink and returns an
 empty string if that is the case.

 {{{#!php
 <?php
 add_filter('old_slug_redirect_url', function($link) {
         if($link === get_the_permalink()) {
                 return '';
         };

         return $link;
 });
 }}}

 This issue might possibly be related: #23074.

 Thanks for looking in to this! Feel free to ask for more details.

--
Ticket URL: <https://core.trac.wordpress.org/ticket/35012>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list