05 Oct How to Redirect a non-WWW to WWW URL in WordPress?
Oct 5, 2016 – 2 min read
Let’s say that we have installed WordPress and we want to redirect a non-WWW URL to WWW URL.
Here are the steps we may follow initially if we want to redirect a non-WWW to WWW URL:
- Log in to the WordPress administration of your website.
- From the main menu open “Settings” -> “General”.
- Change the fields “WordPress Address (URL)” and “Site Address (URL)” from example.com to www.example.com (with https:// or http:// depending on if you use SSL or not).
- Scroll down and press “Save Changes”.
There are cases when after this change, you will be no longer able to access your website (including the administration) through example.com or www.example.com.
Possible issue with the DNS records
Every time when we hit example.com, the request initiated by your web browser will be sent to the nearest DNS server whose job is to forward the request to the IP address of the server where you host your website. But there might be cases when the DNS server misses the information about what to do when somebody requests the domain name with WWW, example: www.example.com. Therefore it cannot redirect non-WWW to WWW URL. From DNS point of view, this is a different domain name and if there is no record for it, it couldn’t know where to forward the request.
Set up a DNS record
Open the administration of your domain name (Name.com, GoDaddy, Domain.com or else) and add the following CNAME record:
Hostname: * Target Host: example.com
This CNAME record is called a Wildcard record because what it does is to tell the DNS servers to forward all requests regarding www.example.com to the IP address associated with the domain name example.com.
Here are a few things to consider checking:
- The web service (Apache, NGINX or else) must be configured correctly — to point to the directory of your WordPress installation. This is only if you administer your own server like Linux or else. If you use shared hosting, this should work by default (the hosting company takes care of that).
- The access rights to the directories and the files corresponding to the WordPress installation must be the right ones because when the web service tries to access a file, it must have the permissions to do it.
If you need assistance with WordPress or your website, contact me.
(The header image is taken from DigitalOcean website.)