Wordpress causing "This webpage has a redirect loop" error remotely
Solution 1
My hosted server settings were forcing mysite.com to www.mysite.com and this was causing the problem. I turned this setting off and everything works now, i'd still like to know how to make it work with this setting turned on, though!
Solution 2
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 :
/**
* avoid redirection loop in redirect_canonical if REQUEST_URI
* contains '/index.php'
**/
/* remove the action set in the hook 'template_redirect' by wordpress */
remove_action('template_redirect', 'redirect_canonical');
/* set a custom action in the hook 'template_redirect' to check REQUEST_URI value */
add_action('template_redirect', 'correct_redirect_canonical');
/* Function to correct the behaviour of redirect_canonical */
function correct_redirect_canonical(){
if(strstr($_SERVER['REQUEST_URI'],'/index.php')===false){
redirect_canonical();
}
}
Hope it helps !
Solution 3
1.- As "My wordpress files are stored in a folder called wordpress" you must edit RewriteBase
and RewriteRule
like this:
RewriteBase /wordpress/
RewriteRule . /wordpress/index.php [L]
UPDATE
2.- Try cleaning all cookies. This simple action (through Firebug) has solved this problem to me sometimes.
UPDATE 3
3.- Try this /index.php in your root directory:
// index.php file in root directory
chdir('wordpress'); // change dir to WP
include 'index.php'; // execute WP with their normal `index.php`
and leave /wordpress
directory as usual (with their normal index.php and .htaccess inside).
I mean don't change any bit of the normal index.php
of WP that it is something like this:
<?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);
/** Loads the WordPress Environment and Template */
require('./wp-blog-header.php');
Solution 4
Note that the infinite redirection problem can also occur when using CloudFlare Flexible SSL. To fix it you need to install the following plugin:
Comments
-
Alex almost 2 years
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 forwp-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'); ?>
-
Alex over 11 yearsWordpress handles all that for you unfortunately. However, I tried it just to be sure and the same error occurred.
-
Igor Parra over 11 years@alex-coady Have you tried with distinct browsers. Also try cleaning all cookies.
-
Alex over 11 yearsI have tried clearing all Cookies yeah, the same error shows in all other Browsers (I tried Firefox, Chrome, Safari).
-
Igor Parra over 11 years@alex-coady Answer updated. I think is the best solution to execute WP from the root dir. Good luck...
-
Alex over 11 yearsThere isn't an
index.php
in the wordpress directory. That file is in my root directory. I think the problem actually lies with my remote server - thanks for your suggestions! -
Igor Parra over 11 years@alex-coady that's why I suggest you leave
wordpress
dir as come out of the box, ie, don't move theirindex.php
outside. Instead make another index.php in your root dir to automaticallychange dir to WP dir
and include theirindex.php
to execute it... check my UPDATE 3.... -
Igor Parra over 11 years@alex-coady I tell you man. I have passed for this, try exactly that I suggest you in UPDATE 3 and you will be ready to party. By my side I already have my beer here... 8)
-
Igor Parra over 11 years@alex-coady Please feedback. Did you resolved the issue. This issue is very common when you try to load WP outside of their directory. Please share! SO is not only to solve personal issues my friend...
-
Elham Gdz over 9 years@IgorParra i move my site from server to local and i update my .htaccess to thing that you say and the error that i get change from The page isn't redirecting properly to Internal Server Error. do you have any idea that i solve my problem? my question in stackoverflow: stackoverflow.com/questions/26860451/…
-
Igor Parra over 9 years@elham-gdz of course not, an Internal Server Error (500+) can mean lot of different things. You must to check the error log of your server.
-
Elham Gdz over 9 years@IgorParra i change my .htaccess settings and i have this error: The page isn't redirecting properly. can you help me to resolve it? when i set MULTISITE to false i can access to wp-admim but when i set it to true i can't access it, how can i fix it, i really need to access my site with it's network, can you help me? do you have any idea?