getting database connection error if connect the site without www

July 27, 2014 1.1k views


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?

2 Answers

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]


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

Have another answer? Share your knowledge.