Wordpress not working with domain name, redirect too many times

February 4, 2018 839 views
WordPress Ubuntu 16.04

I registered a domain name with google's registrar and I have it pointed to digital oceans name servers. This works fine, everything pings correctly.

I am trying to setup a wordpress site and the initial setup works. I can connect with the ip address or the domain name AND it will show the domain name in the address bar. Note that at this point the wordpress settings show the site and wordpress URL as the ip address. Despite this, the domain name still shows in the address bar, which is what I want.

If I make any theme change to the wordpress site, even if I switch out of and back into the initial theme (where everything was working), the address bar will no longer show the domain name. I can use the domain name to get to the website, but the URL will show the IP address, which I don't want.

If I update the URL's in the wordpress admin settings to be the domain name AND update the apache2 config to have servername and alias set to the domain name, then the website will not load. I get an "redirected you too many times" error. Note that the admin page: www.domainname.com/wp-admin works fine, www.domainname.com gives me the redirect issue.

I can switch back the wordpress settings URL's to the ip address and the site works again, but it shows the ip address in the URL bar.

How can I solve this redirect issue and get the site to work with the domain name showing in the URL bar? Thanks!

2 Answers

I think I finally figured this out. I am pretty sure it was simply that I didn't set the wordpress URL and site URL (in wordpress settings) to have 'www.' in front of the domain name.

I also switched to use google nameservers afterwards so I could use their email service.

For anyone future looking at this, including my future self, here is how I set up.

  • Domain registered through google domains
  • Using google's nameservers, which is default. This allows you to use their email service if desired.
  • No domain needs to be setup with digital ocean.
  • Under Custom resource records in google domains, set @ A 1h ip.address.of.droplet and www CNAME 1h domain.name.
  • Not sure if it's required, but I edited the apache2 config file on the digital ocean server. This file for me was "/etc/apache2/sites-enabled/000-default.conf". I added two lines: ServerName domain.name and ServerAlias www.domain.name.

I had a similar problem but caused by following advice by ServerPilot.
Tip: Enter your server's IP address as the app's domain in order to preview the app in your browser using your server's IP address.

This stopped me being able to access my website by the domain name because the wordpress install set its urls to the IP not the domain. So even after my dns propagated properly I got errors when entering the domain. Changing the url settings in wp-config got me access via the domain but I was unable to install multisite getting "Too many redirects" errors even with correct wpconfig and htaccess configuration. Starting from scratch with a new app and NOT following your tip worked fine. Good advice but it should say instead

Tip:Enter your server's domain here, after app creation add the IP address as another of the app's domain in order to preview the app in your browser using your server's IP address.

Have another answer? Share your knowledge.