Help pointing non-www site to www - getting "error establishing a database connection"

Avatar
  • Answered
Hi,

I'm trying to redirect my Wordpress site to point from non-www to www. That is, http://bharari.net should point to http://www.bharari.net.

I tried to do this 2 different ways. Using the 301 redirection method, I modified .htaccess to point non-www to www. When I do this I get a redirect loop error.

So I tried another way. In cPanel, I made the following updates in wp-config.php (added "www" after http://):

define('WP_HOME','http://www.bharari.net');
define('WP_SITEURL','http://www.bharari.net');

I also went to MyPhpAdmin and updated the siteurl value of wp_options table for the database to include "www".

After I do all this, I get an "Error establishing a database connection" when I visit my web site.

what am I doing wrong? I've undone the changes for now.

Many thanks!
Avatar
JacobIMH
Hello bharari, and thank you for your question. I went ahead and corrected this for you. In order to get WordPress to properly always append the www. before your domain name both of these settings have to be set in the database in your wp_options table: siteurl = http://www.bharari.net home = http://www.bharari.net I think the problems you were having were that you were trying to force the www with your .htaccess file prior to setting up WordPress to use this, so when it attempted to connect over www WordPress internally would redirect it back to without that appended, which would lead to a redirect loop. I've left the options commented out in your wp-config.php file since they're getting included directly from the database now. I've also left in the .htaccess code to force using the www which isn't required to have it work with WordPress, but if you had any other pages outside of WordPress on your site this would allow them to all be over www now as well. Please let us know if you have any further questions at all. - Jacob