1

I'm really battling with something here. I'm trying to change my site to go from www. to non-www, and also http:// to https://

I've updated the settings in options-general.php (WordPress Address (URL) and Site Address (URL)). Both of these are using the non-www version, and also https:// now.

I've also updated the cookie setting in wp-config.php:

define( 'COOKIE_DOMAIN', 'mysite.co.uk' );

I can access the wp-admin just fine on https AND the non-www version. However, index.php just wants to keep me going in an infinite loop, reloading the homepage until it the browser gives up. I can't believe how hard this has been!

Anyone got any suggestions on what to try? I've spent 3 hours so far, on something that should have taken minutes.

For what it's worth, I have disabled ALL the plugins (in case it was one of them being weird), but still, it doesn't work.

It's probably worth mentioning that this has to be a WP issue, as editing index.php work fine if I just put this in it:

<?php
/**
 * Front to the WordPress application. This file doesn't do anything, but loads
 * wp-blog-header.php which does and tells WordPress to load the theme.
 *
 * @package WordPress
 */

/**
 * Tells WordPress to load the WordPress theme and output it.
 *
 * @var bool
 */
define('WP_USE_THEMES', true);

echo header();
echo "FOO";

UPDATE: Interestingly, I thought I would just go through the code and try to see where its screwing up. It gets to /wp-includes/template-loader.php, and then gets into the loop here:

do_action( 'template_redirect' );

...I don't knoew where it goes after that though? (to try and debug more)

UPDATE 2: I just installed this plugin: https://wordpress.org/support/plugin/debug-wp-redirect/ . Its super old, but it has shown me where the redirect is coming from:

Debug WP Redirect
Location: https://mysite.co.uk/
Status: 301
Backtrace:

    File: /home/rachel/web/mysite.co.uk/public_html/wp-includes/class-wp-hook.php
    Line: #298
    Function: redirect_canonical
    Arguments:

    array(1) {
      [0]=>
      string(27) "http://mysite.co.uk/"
    }

I just don't know why its failing (and using http instead of https here, which I guess is where the loop is coming from)

UPDATE 3: I don't know why, but this ONLY happens on the homepage!

http://www.foo.co.uk/wires-eyewear/
http://foo.co.uk/wires-eyewear/
https://www.foo.co.uk/wires-eyewear/
https://foo.co.uk/wires-eyewear/

All work fine. But:

http://www.foo.co.uk
http://foo.co.uk
https://foo.co.uk/
http://foo.co.uk

...all get stuck in an infinite loop. Eugh, this is so frustrating!

UPDATE 4: I've managed to get a stack trace, but I don't understand what is going on.

PHP message:            File: /home/rachel/web/ladympresents.co.uk/public_html/wp-includes/class-wp-hook.php

PHP message:            Line: #298

PHP message:            Function: debug_wp_redirect

PHP message:            Arguments:



PHP message: array(2) {
  [0]=>
  string(28) "https://ladympresents.co.uk/"
  [1]=>
  int(301)
}

PHP message:
PHP message:            File: /home/rachel/web/ladympresents.co.uk/public_html/wp-includes/plugin.php

PHP message:            Line: #203

PHP message:            Class: #WP_Hook

PHP message:            Function: apply_filters

PHP message:            Arguments:



PHP message: array(2) {
  [0]=>
  string(28) "https://ladympresents.co.uk/"
  [1]=>
  array(2) {
    [0]=>
    string(28) "https://ladympresents.co.uk/"
    [1]=>
    int(301)
  }
}

PHP message:
PHP message:            File: /home/rachel/web/ladympresents.co.uk/public_html/wp-includes/pluggable.php

PHP message:            Line: #1181

PHP message:            Function: apply_filters

PHP message:            Arguments:



PHP message: array(3) {
  [0]=>
  string(11) "wp_redirect"
  [1]=>
  string(28) "https://ladympresents.co.uk/"
  [2]=>
  int(301)
}

PHP message:
PHP message:            File: /home/rachel/web/ladympresents.co.uk/public_html/wp-includes/canonical.php

PHP message:            Line: #516

PHP message:            Function: wp_redirect

PHP message:            Arguments:



PHP message: array(2) {
  [0]=>
  string(28) "https://ladympresents.co.uk/"
  [1]=>
  int(301)
}

PHP message:
PHP message:            File: /home/rachel/web/ladympresents.co.uk/public_html/wp-includes/class-wp-hook.php

PHP message:            Line: #298

PHP message:            Function: redirect_canonical

PHP message:            Arguments:



PHP message: array(1) {
  [0]=>
  string(31) "http://www.ladympresents.co.uk/"
}

PHP message:
PHP message:            File: /home/rachel/web/ladympresents.co.uk/public_html/wp-includes/class-wp-hook.php

PHP message:            Line: #323

PHP message:            Class: #WP_Hook

PHP message:            Function: apply_filters

PHP message:            Arguments:

I'm thinking this is now more and issue with the www. being taken out of the URL. I just don't get why though. I have every single plugin disabled, I've fully migrated the DB over (I even tried using a plugin to search and replace the DB and replace the old URL with the new one), and still the homepage refuses to work! There is either a major bug I've stumbled across, or something else at play. This is the bit this is baffling me:

PHP message:
PHP message:            File: /home/rachel/web/ladympresents.co.uk/public_html/wp-includes/class-wp-hook.php

PHP message:            Line: #298

PHP message:            Function: redirect_canonical

PHP message:            Arguments:
PHP message: array(1) {
  [0]=>
  string(31) "http://www.ladympresents.co.uk/"
}

The URL's are perfect up to that part, and then it randomly changes it back to not only http://, but also add's the www. bit in again!

UPDATE 4: So the plot thickens! It now turns out the problem is when using a custom page for the homepage!

If I change the Front page displays to "Front page displays" (instead of "A static page (select below)" , then it works... but obviously I have a rubbish looking homepage, that has nothing we need on there. I've tested this with different themes, and they all have the same problem. ARGH!

1 Answer 1

1

Add the following to your .htaccess..

# force https on the front of the site
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

ref https://stackoverflow.com/questions/4398951/force-ssl-https-using-htaccess-and-mod-rewrite

if on nginx the advice is for the following..

server {
listen 80;
server_name yoursite.com www.yoursite.com;
return 301 https://yoursite.com$request_uri;
}

refer to http://www.wpbeginner.com/wp-tutorials/how-to-add-ssl-and-https-in-wordpress/

for other areas such as the site settings changes for https.

11
  • Thanks Justin. I'm actually on nginx (I've updated the tags above). However, it has to be a wordpress issue. If I create an index.html and then call that in the browser, it works fine (in both http and https). It has to be something in WP that is trying to direct back to the www (or http version), and thus getting stuck in a loop. How do you track that down though? :/ It's probably worth mentioning as well, that it works fine when I was on the www. version (even with https). Unfortunately I need to move it over to the non-www version though Apr 28, 2017 at 11:23
  • I've added an update have a look at wpbeginner.com/wp-tutorials/…
    – Justin
    Apr 28, 2017 at 12:34
  • thanks, but I've already done/tried all of that :( In my opening post, I have made some updates. The ONLY page that seems to have a melt-down, is the homepage. The rest all work fine. Apr 28, 2017 at 12:40
  • from the stack and the redirect_canonical looks like wordpress believes that the https://mysite.co.uk/ does not exist based on exact WordPress query. Have you gone through your database looking for references to http://mysite.co.uk/ and changed out to https://mysite.co.uk/ careful to use something like wp-migrate-db to not mess up your string lengths.
    – Justin
    Apr 28, 2017 at 17:01
  • 1
    yeah, I do moves of sites all the time, so I'm pretty versed in how to move them. This one just has me baffled though. I've now pinned it down to the Front page displays setting being set as A static page (select below). If I set it to Your latest post, then it shows - but the page looks rubbish, as it's obviously not the page we've designed to be on the front end :( Apr 28, 2017 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.