Changing the Site URL in WordPress
“Add WWW: Make http://ankit.jainji.com/ redirect to http://www.ankit.jainji.com/”
i.e. the site should always redirect to the domain name prefixed with www.
I installed wordpress on it and set it up completely.
After couple of days I thought of not having WWW in the beginning as it is a subdomain and subdomains generally don’t have WWW prefixed with them. It was making the domain name longer too. So I thought of removing it.
I went back to dreamhost panel and modified the domain to select the last option
“Remove WWW: Make http://www.ankit.jainji.com/ redirect to http://ankit.jainji.com/”
I then tried to open the website in a browser and to my surprise it did not open at all. I noticed in the status bar of the browser that it was trying to navigate to www.ankit.jainji.com, within a second it was trying to navigate to ankit.jainji.com and it kept on happening i.e. it was trying to find the URL where to navigate to but was unable to resolve it.
After thinking for a while, I realized that wordpress also stores site url within it. So, when I first installed wordpress on the domain, the domain name was www.ankit.jainji.com. That means wordpress has stored this domain name in its database. Later, I changed dreamhost to redirect it to ankit.jainji.com i.e. without www.
So what was happening was that dreamhost was redirecting it to ankit.jainji.com and wordpress was again redirecting it to www.ankit.jainji.com so an infinite loop in resolving the url.
I encountered this error for the first time in my life. Solution to this problem is extremely easy too.
We can simply modify the Site URL property in wordpress.
Since we cannot access wp-admin, we are either required to access it via ftp or we can change it in the database via mySql access.
Different methods have been explained here but the one that I preferred and is really quick is by adding two properties in wp-config.php
We have to add these two lines to our wp-config.php, where “example.com” is the new location of our site (http://ankit.jainji.com in my case)
These properties are also useful when we move our blog to a completely new domain i.e. from http://abc.com to http://def.com.
Really quick, isn’t it?? Hope it helps!!