InMotion Hosting Support Center

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

Category: Wordpress

2013-01-25 2:57 pm EST

Hits: 774

I'm trying to redirect my Wordpress site to point from non-www to www. That is, should point to

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://):


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!

You must login before you can ask a follow up question.

You must login before you can submit an answer.

Best answer chosen by User


9,968 Points
2013-01-25 3:52 pm EST
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 =
home =

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

You must login before you can post a comment about this answer.

Like this Question?

Need more Help?


Ask the Community!

Get help with your questions from our community of like-minded hosting users and InMotion Hosting Staff.

Current Customers

Chat: Click to Chat Now E-mail:
Call: 888-321-HOST (4678) Ticket: Submit a Support Ticket

Not a Customer?

Get web hosting from a company that is here to help. Sign up today!