Why is apache much slower with naked domain?

I’m running a droplet with apache and wordpress installed on it. Basic load testing with the ab tool shows that the requests per second are much lower when the naked domain is used. For example:

ab -kc 10 -n 100 

results in an average connection time of >2000ms and

ab -kc 10 -n 100 

would result in an average connection time of ~700ms. Also htop shows that the cpu is at 100% for the test with the naked domain and for the www. domain the cpu stays relatively low all the time.


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

The error log shows unfortunately nothing and the .htaccess only contains the standard wordpress entry. However I have a suspicion that the problem is related to the WP Super Cache plugin. The small droplet runs a relatively heavy wordpress site. For some reason the cached static content is not loaded when the naked domain is accessed, instead the dynamic PHP content is called for every request. For now the problem is solved with following .htaccess rule:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

What’s your .htaccess look like? Is it perhaps redirecting in a loop until it hits the threshold and gives up? The apache error log will likely have some warning on this. I’d start there first.