[wp-trac] [WordPress Trac] #33581: Use history.replaceState instead of 301 redirects for canonical urls

WordPress Trac noreply at wordpress.org
Sat Aug 29 02:19:51 UTC 2015

#33581: Use history.replaceState instead of 301 redirects for canonical urls
 Reporter:  peterwilsoncc  |       Owner:
     Type:  enhancement    |      Status:  new
 Priority:  normal         |   Milestone:  Awaiting Review
Component:  Canonical      |     Version:
 Severity:  normal         |  Resolution:
 Keywords:  needs-patch    |     Focuses:  javascript, performance
Changes (by peterwilsoncc):

 * keywords:  reporter-feedback => needs-patch


 Replying to [comment:1 johnbillion]:
 > How would this work with browsers that don't support history state?

 These browsers would display the ugly permalink:


 According to [http://caniuse.com/#feat=history caniuse], global usage
 stats for the most popular browsers without support are:

 - IE8: 1.58%
 - IE9: 1.25%
 - Opera mini: 4.62%
 - Android 4: 0.28%
 - Android 4.1: 0.78%

 Feature detection is used to prevent JavaScript errors in these browsers.

 Experimenting with a [https://wordpress.org/plugins/rapid-canonical-urls/
 plugin], the logic I have used is:

 1. 301 redirect if
   - `true == is_404()`
   - destination domain differs from the requested domain (history state
 doesn't work)
   - the visitor hits an old slug, eg `smaple-slug` has been corrected to
 `sample-slug` after publishing (`is_404`)
   - destination domain has been filtered and changed in any way. No way to
 predict what is meant to happen.
 2. history.replaceState if
   - `!is_404()`, taking the redirect out will produce the content
   - destination URL is always the value returned by the redirect function
 - canonical meta tag may differ.

Ticket URL: <https://core.trac.wordpress.org/ticket/33581#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list