23 September 2019

How to differentiate between a redirection made by Apache vs Wordpress


When you change WordPress installation you may find yourself locked out by this scenario
1. You had all running well with SSL and redirections in place to https
2. You move the installation and temporarily you don't have SSL certificates
3. Redirection to https is happening and you can't administer your wordpress installation
4. You know where the redirection is happening, edit that, but it keeps happening.

Now is when  you have to look better to what is really happening.

I'll go to the point. Look at the output of the command

#  curl -sLD -  the-url-to-check     | head -30

Some examples:

### Here Wordpress is doing a redirection to https
$ curl -sLD -  http://URLtotest/
HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Content-Length: 0
Connection: keep-alive
Keep-Alive: timeout=15
Date: Mon, 23 Sep 2019 17:14:12 GMT
Server: Apache
X-Powered-By: PHP/7.2.22
X-Redirect-By: WordPress
Location: https://URLtotest/


### Here Apache is doing a redirection from  www to non-www  (there is no X-Redirect-By: WordPress)
$ curl -sLD -  http://www.URLtotest.com/ | head -30
HTTP/1.1 301 Moved Permanently
Content-Type: text/html; charset=UTF-8
Content-Length: 0
Connection: keep-alive
Keep-Alive: timeout=15
Date: Mon, 23 Sep 2019 17:18:49 GMT
Server: Apache
X-Powered-By: PHP/7.2.22
Location: http://URLtotest.com/

HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=15
Date: Mon, 23 Sep 2019 17:18:50 GMT
Server: Apache
Expires: Mon, 23 Sep 2019 18:18:50 GMT
Pragma: public
Cache-Control: max-age=3600, public
X-Powered-By: W3 Total Cache/0.9.7
Last-Modified: Thu, 01 Jan 1970 00:00:00 GMT
ETag: "7118495d6d84053e693f5ca7f39b74a7"


If you cannot run that command, you can use this web http://www.redirect-checker.org

It provides more information than other webs (look at the console output).




If Wordpress itself is the component doing the redirection, you can
on: wp-includes/functions.php
add these lines:
remove_action('template_redirect', 'redirect_canonical');
remove_filter('template_redirect','redirect_canonical');

However that doesn't mean that you will be able to login on wp-admin, for that you have to

On: wp-config.php
change the true for false
define('FORCE_SSL_ADMIN', true);


Let me know if it helped you.
Too Cool for Internet Explorer