I have a WordPress website which redirects the non-www to the www version, but when redirecting there is a delay of 6 seconds before downloading any content. When going directly to the www version the website starts downloading at 2.8 seconds and finishes completely in under 5 seconds while if i go to the non-www version it takes almost 8 seconds to complete the webpage. This is done by clearing cache after every attempt. I can understand the 2.8 seconds is for finding the server and the server generating PHP, but whats causing the additional 3 seconds when redirecting? I used to use a mod_rewrite redirect but later I found out that Wordpress handles redirection on its own so I'm wondering if Wordpress is causing that. If I use mod_rewrite then Wordpress just causes an infinite loop when requesting the website.
Use htaccess redirect. It's almost instant. Wordpress has to connect to the database and read the file and send the redirect. Lots of work for the server. With htaccess, wordpress never even sees the incorrect request, Apache does it on its own. Much more efficient.
Thanks for the info, would you happen to know how to disable the WordPress redirect, I get an infinite 301 loop if I also add a mod_rewrite redirect with the WordPress redirect.
Disable any redirection plugin you have in your WP, and only use the .htaccess redirect. If it's still redirecting in some way, then you need to adjust the WP database to have the correct URL applied as its default URL, whether that be non-www or www. Make sure the .htaccess redirects to the one you want (non-www or www), and make sure the WP database has this too in its config.