I have a Wordpress site that works perfectly well in development (at mysite.dev
), however when I deploy it to my remote server (mysite.com
) it throws the 'This webpage has a redirect loop' error.
I can see in the loading bar that the browser is trying www.mysite.com then mysite.com then www.mysite.com again and again, however I'm not sure if this is relavant or not.
If my Wordpress database configuration is incorrect, I get the Error establishing a database connection message, however when everything is set correctly it breaks in this re-direct loop thing.
I have changed the field in the database (siteurl
) to reflect the remote settings (http://mysite.com/wordpress
).
Note: My wordpress files are stored in a folder called wordpress
in my root directory except for wp-config.php
, index.php
and .htaccess
.
Any ideas?
.htaccess contents:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
index.php:
<?php
/**
* @package WordPress
*/
define('WP_USE_THEMES', true);
require('./wordpress/wp-blog-header.php');
?>
I had the same problem, the answer was the
.htaccess
file and the redirects there. It seems that the theme/plugins I was using wanted its own code which was similar to that on the wordpress site forhtaccess
. I looked through the plugin and found the code it referenced and changed that in thehtaccess
file. Now it works.I had the exact same problem (a redirection loop after migrating to a new server).
But it was not a problem with the configuration values siteurl and home, neither was it an issue with the .htaccess file. I tried all that. And it was also not a problem about the 'www' added to the URL.
After some researchs I found that the loop was caused by infinite calls to the redirect_canonical function (in wp-inclue/canonical.php). But it was not a bug from wordpress. Some Php configs set the $_SERVER['REQUEST_URI'] in a "wrong way" when you acces your root url. Example : On my server, when I go to http://example.com/ the $_SERVER['REQUEST_URI'] is set to '/index.php' instead of just '/' This is confusing for redirect_canonical because this function always try to redirect to the "better" url it knows for a page. And the better url for the root of your site is '/'. On my server, each time redirect_canonical tried to redirect to '/' it failed, and tried again until an infinite redirect loop was found.
To correct this bug, you can either modify your server configuration - I don't personnaly know how to do that, but I know it is possible - or if you can't change it, just add this code in a custom plugin :
Hope it helps !
Are you using a plugin like Redirection which tracks URL changes? This might have created a loop where it redirects mysite.dev/page/ to mysite.com/page/ and mysite.com to mysite.dev. Happened to me before!