Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I was using pingdom to test the load speed on a site I'm working on and got different results for www vs non www. Wordpress automatically redirects to either www or non www depending on the settings.

For the site in question its set to use non www and when tested in pingdom it came back with a 1 second result. Shortly after that I tested the site again with pingdom now with www and it came back as 3 seconds.

I contacted my host (hostgator) cause I thought it might have been a weird dns issue and to be honest I'm not super clued up on dns related issues.

They told me that the redirect happens while wordpress is already loading so when I go to www it loads wordpress then redirects so it almost has to load the site twice. They suggested I use a standard htaccess redirect at the top of the htacess file.

After doing that I tested the site again with both versions and they both seem to load at around 1 second.

Now finally after all that my question is why does this happen? At what point does the wordpress default redirect kick in. Should I just by default add the redirect myself to the top of the htaccess file for all sites?

Basically just looking to find out more about how wordpress handles that redirect, if someone would perhaps link me to a codex page about it or a blog article that would be amazing.

share|improve this question

1 Answer 1

You ran into a feature of WordPress known as Canonical Redirect. The idea is that each page on your website will only have one URL. But since it is possible to get to a page with a different URL, it will force a redirect to the "true" URL. The reason for this is to prevent duplicate results in search engines because of different URLs.

Some common cases of alternative URLs are:

  • You are missing the ending /
  • You use an alternative domain name
  • You use a query var example.com/?p=133 instead of the pretty URL example.com/my-blog-post/

As for the domain name, I would force it from the .htaccess file instead of WordPress. It is a good idea to have the canonical URLs and Apache will handle it faster than WordPress with regards to the domain name.

More information on it:

  1. WP Codex entry on redirect_canonical() function
  2. Canonical URLs regarding Google and WordPress
  3. How to disable canonical redirects
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.