getting database connection error if connect the site without www

  • Posted July 27, 2014


I’m running Wordpress latest package on Ubuntu 14.04 with apache and mysql server. Everyting was running perfectly, but this evening I’m getting database connection error without using www.

Here is sites: (Failing) (Running perfectly)

I’m also using monit for keep running whole system. So the monit status is returning everyting is perfect.

So what ist the problem? How can I solve this?


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.

Thank you so much! I removed the Wp Super Cache plugin with all setting files. Then re-enabled. So, it worked!

Here is what I got from both sites:

<!-- Dynamic page generated in 43.190 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2014-07-28 01:43:15 -->

<!-- super cache -->

<!-- Dynamic page generated in 0.602 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2014-07-28 06:10:50 -->

<!-- super cache -->

WP super cache maybe the cause. Seems like it have different caches for non-www and www version.

If you don’t want to deal with it right now, just add a rewrite rule to redirect non-www to www

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]