Title: Locked-out loop
Last modified: August 20, 2016

---

# Locked-out loop

 *  [una_s88](https://wordpress.org/support/users/una_s88/)
 * (@una_s88)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/)
 * Hi,
 * I’ve setup a redirection link by accident on my localhost which directs to an
   online version which I’m trying to setup, however that online version directs
   to the localhost, so I’m kind of locked out with no way of logging in to my wp-
   admin. Is there a way I can manually change or reset this setting on my local
   files & if so, which file and how?
 * HELP ME!
 * Nik

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/locked-out-loop/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/locked-out-loop/page/2/?output_format=md)

 *  [Jeff Clark](https://wordpress.org/support/users/jclark32/)
 * (@jclark32)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541787)
 * How did you setup the redirect? Through the backend
 *  Thread Starter [una_s88](https://wordpress.org/support/users/una_s88/)
 * (@una_s88)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541788)
 * Yup – in the options section
 *  [Jeff Clark](https://wordpress.org/support/users/jclark32/)
 * (@jclark32)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541793)
 * Do you have access to the htaccess file? My guess is it would write it there,
   its that or a php redirect using wp_redirect()
 *  Thread Starter [una_s88](https://wordpress.org/support/users/una_s88/)
 * (@una_s88)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541808)
 * I do indeed, i’ve got it open now – what should I be looking for?
    I really appreciate
   your help! Thanks!
 *  [Jeff Clark](https://wordpress.org/support/users/jclark32/)
 * (@jclark32)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541809)
 * Can you post it here?
 *  Thread Starter [una_s88](https://wordpress.org/support/users/una_s88/)
 * (@una_s88)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541810)
 *     ```
       <?php
   
       class Red_Htaccess
       {
       	var $settings;
       	var $items;
   
       	function Red_Htaccess ($settings)
       	{
       		foreach ($settings AS $key => $value)
       			$this->settings[$key] = $value;
       	}
   
       	function encode_from ($url)
       	{
       		return '^'.$this->encode ($url).'$';
       	}
   
       	function encode2nd ($url)
       	{
       		$url = urlencode ($url);
       		$url = str_replace ('%2F', '/', $url);
       		$url = str_replace ('%3A', ':', $url);
       		$url = str_replace ('+', '%20', $url);
       		$url = str_replace ('%24', '$', $url);
       		return $url;
       	}
   
       	function encode ($url)
       	{
       		$url = urlencode ($url);
       		$url = str_replace ('%2F', '/', $url);
       		$url = str_replace ('+', '%20', $url);
       		$url = str_replace ('.', '\\.', $url);
       		return $url;
       	}
   
       	function encode_regex ($url)
       	{
       		$url = str_replace (' ', '%20', $url);
       		$url = str_replace ('.', '\\.', $url);
       		$url = str_replace ('\\.*', '.*', $url);
       		$url = str_replace ('%24', '$', $url);
       		return $url;
       	}
   
       	function add_referrer ($item, $match)
       	{
       		$from = $this->encode_from (ltrim ($item->url, '/'));
       		if ($item->regex)
       			$from = $this->encode_regex (ltrim ($item->url, '/'));
   
       		if (($match->url_from || $match->url_notfrom) && $match->referrer)
       		{
       			$this->items[] = sprintf ('RewriteCond %%{HTTP_REFERER} %s [NC]', ($match->regex ? $this->encode_regex ($match->referrer) : $this->encode_from ($match->referrer)));
   
       			if ($match->url_from)
       			{
       				$to = $this->target ($item->action_type, $match->url_from, $item->action_code, $item->regex);
       				$this->items[] = sprintf ('RewriteRule %s %s', $from, $to);
       			}
   
       			if ($match->url_notfrom)
       			{
       				$to = $this->target ($item->action_type, $match->url_notfrom, $item->action_code, $item->regex);
       				$this->items[] = sprintf ('RewriteRule %s %s', $from, $to);
       			}
       		}
       	}
   
       	function add_agent ($item, $match)
       	{
       		$from = $this->encode (ltrim ($item->url, '/'));
       		if ($item->regex)
       			$from = $this->encode_regex (ltrim ($item->url, '/'));
   
       		if (($match->url_from || $match->url_notfrom) && $match->user_agent)
       		{
       			$this->items[] = sprintf ('RewriteCond %%{HTTP_USER_AGENT} %s [NC]', ($match->regex ? $this->encode_regex ($match->user_agent) : $this->encode2nd ($match->user_agent)));
   
       			if ($match->url_from)
       			{
       				$to = $this->target ($item->action_type, $match->url_from, $item->action_code, $item->regex);
       				$this->items[] = sprintf ('RewriteRule %s %s', $from, $to);
       			}
   
       			if ($match->url_notfrom)
       			{
       				$to = $this->target ($item->action_type, $match->url_notfrom, $item->action_code, $item->regex);
       				$this->items[] = sprintf ('RewriteRule %s %s', $from, $to);
       			}
       		}
       	}
   
       	function add_url ($item, $match)
       	{
       		$to   = $this->target ($item->action_type, $match->url, $item->action_code, $item->regex);
       		$from = $this->encode_from (ltrim ($item->url, '/'));
       		if ($item->regex)
       			$from = $this->encode_regex (ltrim ($item->url, '/'));
   
       		if ($to)
       			$this->items[] = sprintf ('RewriteRule %s %s', $from, $to);
       	}
   
       	function action_random ($data, $code, $regex)
       	{
       		// Pick a WP post at random
       		global $wpdb;
   
       		$post = $wpdb->get_var ("SELECT ID FROM {$wpdb->posts} ORDER BY RAND() LIMIT 0,1");
       		$url  = parse_url (get_permalink ($post));
   
       		return sprintf ('%s [R=%d,L]', $this->encode ($url['path']), $code);
       	}
   
       	function action_pass ($data, $code, $regex)
       	{
       		if ($regex)
       			return sprintf ('%s [L]', $this->encode2nd ($data), $code);
       		else
       			return sprintf ('%s [L]', $this->encode2nd ($data), $code);
       	}
   
       	function action_error ($data, $code, $regex)
       	{
       		if ($code == '410')
       			return '/ [G,L]';
       		return '/ [F,L]';
       	}
   
       	function action_url ($data, $code, $regex)
       	{
       		if ($regex)
       			return sprintf ('%s [R=%d,L]', $this->encode2nd ($data), $code);
       		else
       			return sprintf ('%s [R=%d,L]', $this->encode2nd ($data), $code);
       	}
   
       	function target ($action, $data, $code, $regex)
       	{
       		$target = 'action_'.$action;
   
       		if (method_exists ($this, $target))
       			return $this->$target ($data, $code, $regex);
       		return '';
       	}
   
       	function add ($item)
       	{
       		$target = 'add_'.$item->match_type;
   
       		if (method_exists ($this, $target))
       			$this->$target ($item, $item->match);
       	}
   
       	function generate ($name)
       	{
       		// Head of redirection section - do not localize this
       		global $redirection;
   
       		$text[] = '# Created by Redirection Module: '.$name;
       		$text[] = '# '.date ('r');
       		$text[] = '# Redirection '.$redirection->version ().' - http://urbangiraffe.com/plugins/redirection/';
       		$text[] = '';
   
       		// Default blocked files - I can't think of a reason not to block these
       		$text[] = '<Files .htaccess,.svn>';
       		$text[] = 'order allow,deny';
       		$text[] = 'deny from all';
       		$text[] = '</Files>';
       		$text[] = '';
   
       		// PHP options
       		if (isset ($this->settings['error_level']) && $this->settings['error_level'] != 'default')
       			$text[] = 'php_value error_reporting '.($this->settings == 'none' ? '0' : 'E_ALL');
   
       		if (isset ($this->settings['memory_limit']) && $this->settings['memory_limit'] != 0)
       			$text[] = 'php_value memory_limit '.$this->settings['memory_limit'].'M';
   
       		if ($this->settings['allow_ip'] || $this->settings['ban_ip'])
       		{
       			$text[] = '';
       			$text[] = 'order allow,deny';
       			if ($this->settings['ban_ip'])
       			{
       				$ips = array_filter (explode (',', $this->settings['ban_ip']));
       				if (count ($ips) > 0)
       				{
       					foreach ($ips AS $ip)
       						$text[] = 'deny from '.$ip;
       				}
       			}
   
       			if ($this->settings['allow_ip'])
       			{
       				$ips = array_filter (explode (',', $this->settings['allow_ip']));
       				if (count ($ips) > 0)
       				{
       					foreach ($ips AS $ip)
       						$text[] = 'allow from '.$ip;
       				}
       			}
       			else
       				$text[] = 'allow from all';
       		}
   
       		// mod_rewrite section
       		$text[] = '';
       		$text[] = 'Options +FollowSymlinks';
       		$text[] = '';
       		$text[] = '<IfModule mod_rewrite.c>';
   
       		if ($this->settings['canonical'] != 'default')
       		{
       			$text[] = 'RewriteEngine On';
       			$base   = $this->settings['site'];
       			if ($base == '')
       				$base = get_option ('home');
   
       			$parts = parse_url ($base);
       			$base  = str_replace ('www.', '', $parts['host']);
   
       			if ($this->settings['canonical'] == 'nowww')
       			{
       				$text[] = 'RewriteCond %{HTTP_HOST} ^www\.'.str_replace ('.', '\\.', $base).'$ [NC]';
       				$text[] = 'RewriteRule ^(.*)$ http://'.$base.'/$1 [R=301,L]';
       			}
       			else if ($this->settings['canonical'] == 'www')
       			{
       				$text[] = 'RewriteCond %{HTTP_HOST} ^'.str_replace ('.', '\\.', $base).'$ [NC]';
       				$text[] = 'RewriteRule ^(.*)$ http://www.'.$base.'/$1 [R=301,L]';
       			}
   
       			$text[] = '';
       		}
   
       		if ($this->settings['strip_index'] == 'yes')
       		{
       			$text[] = 'RewriteCond %{THE_REQUEST} (.*)index\.(php|htm|html)\ HTTP/';
       			$text[] = 'RewriteRule ^(.*)index\.(php|html|htm)$ $1 [R=301,NC,L]';
       			$text[] = '';
       		}
   
       		// Add redirects
       		if (is_array ($this->items))
       			$text = array_merge ($text, $this->items);
   
       		// End of mod_rewrite
       		$text[] = '</IfModule>';
       		$text[] = '';
   
       		if ($this->settings['raw'])
       			$text[] = $this->settings['raw'];
   
       		// End of redirection section
       		$text[] = '# End of Redirection';
       		$text[] = '';
   
       		$text = implode ("\r\n", $text);
       		$text = str_replace ("\r\n\r\n\r\n", "\r\n", $text);
       		$text = str_replace ("\r\n\r\n\r\n", "\r\n", $text);
       		return $text;
       	}
   
       	function save ($filename, $name)
       	{
       		$text = $this->generate ($name);
   
       		// Does the file already exist?
       		if (file_exists ($filename))
       		{
       			$existing = @file_get_contents ($filename);
   
       			// Remove any existing Redirection module
       			$text .= preg_replace ('@# Created by Redirection Module: '.$name.'(.*?)# End of Redirection@s', '', $existing);
       		}
   
       		$file = @fopen ($filename, 'w');
       		if ($file)
       		{
       			$text = str_replace ("\r\n\r\n\r\n", "\r\n", $text);
       			$text = str_replace ("\r\n\r\n\r\n", "\r\n", $text);
   
       			fwrite ($file, $text);
       			fclose ($file);
       			return true;
       		}
   
       		return false;
       	}
       }
       ```
   
 * _[Please post code or markup between backticks or use the code button. Or better
   still – use a [pastebin](http://pastebin.com/). Your posted code may now have
   been permanently damaged/corrupted by the forum’s parser.]_
 *  [Jeff Clark](https://wordpress.org/support/users/jclark32/)
 * (@jclark32)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541812)
 * Try removing this
 * PLEASE MAKE SURE YOU KEEP A BACKUP OF THIS FILE SO WE CAN ROLL IT BACK IF NEEDED
 *     ```
       // Add redirects
       if (is_array ($this->items))
       $text = array_merge ($text, $this->items);
   
       // End of mod_rewrite
       $text[] = '</IfModule>';
       $text[] = '';
   
       if ($this->settings['raw'])
       $text[] = $this->settings['raw'];
   
       // End of redirection section
       $text[] = '# End of Redirection';
       $text[] = '';
   
       $text = implode ("\r\n", $text);
       $text = str_replace ("\r\n\r\n\r\n", "\r\n", $text);
       $text = str_replace ("\r\n\r\n\r\n", "\r\n", $text);
       return $text;
       }
   
       function save ($filename, $name)
       {
       $text = $this->generate ($name);
   
       // Does the file already exist?
       if (file_exists ($filename))
       {
       $existing = @file_get_contents ($filename);
   
       // Remove any existing Redirection module
       $text .= preg_replace ('@# Created by Redirection Module: '.$name.'(.*?)# End of Redirection@s', '', $existing);
       }
       ```
   
 * _[Please post code & markup between backticks or use the code button. Your posted
   code may now have been permanently damaged by the forum’s parser.]_
 *  [Jeff Clark](https://wordpress.org/support/users/jclark32/)
 * (@jclark32)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541813)
 * Actually this is a giant class, I missed that. Lets just try removing the entire
   thing and then change your redirects to the proper ones and then reupload the
   file. That should work.
 *  Thread Starter [una_s88](https://wordpress.org/support/users/una_s88/)
 * (@una_s88)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541817)
 * Im afraid its still re-directing.. I’ve changed it back to the backup.. Could
   it be another file?
 *  [Jeff Clark](https://wordpress.org/support/users/jclark32/)
 * (@jclark32)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541819)
 * What plugin are you using?
 *  Thread Starter [una_s88](https://wordpress.org/support/users/una_s88/)
 * (@una_s88)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541820)
 * contact form 7
    contact form plugin gecka submenu iire social lite lightbox plus
   nexgen gallery options framework photomosaic for wordpress portfolio post type
   redirection social media widget synved options use any font wordpress custom 
   sidebar wordpress move
 *  [Jeff Clark](https://wordpress.org/support/users/jclark32/)
 * (@jclark32)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541822)
 * hmm if we disable redirection plugin that should allow you to get back in but
   I am not 100 percent if it will delete all your redirects or not. I am really
   struggling to see why removing the htaccess file doesnt work.
 * If you want to try removing your redirection plugin manually that could work.
   NOTE if you do this you could loose all your redirects. Make sure you backup 
   the db if you try this.
 * Do you have more then one htaccess file?
 *  Thread Starter [una_s88](https://wordpress.org/support/users/una_s88/)
 * (@una_s88)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541833)
 * Ok.. so I removed the code you pasted above from the htaccess files on both my
   server and the new one I am attempting to move the site to.
    Now the ‘locked 
   out’ redirect loop is broken. But the wp admin on my MAMP server is redirecting
   to the new server which is allowing me to log into WordPress but its a new install
   and not reading my content.. and I still cant log in to the backend on MAMP..
   any thoughts?
 *  [Jeff Clark](https://wordpress.org/support/users/jclark32/)
 * (@jclark32)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541834)
 * Did you do it in MAMP as well?
 *  Thread Starter [una_s88](https://wordpress.org/support/users/una_s88/)
 * (@una_s88)
 * [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/#post-3541835)
 * Yeah I did thats whats strange.. I just deleted the one out of MAMP and copied
   the same one from the new server in.. now its not coming up with the admin screen
   when i direct to wp-admin but redirects straight to this:
 * [http://nicolasgaillard.com/wordpress/wp-login.php?redirect_to=http%3A%2F%2Flocalhost%3A81%2Fwp-admin%2F&reauth=1](http://nicolasgaillard.com/wordpress/wp-login.php?redirect_to=http%3A%2F%2Flocalhost%3A81%2Fwp-admin%2F&reauth=1)
 * before it was allowing me to input the admin credentials and only then redirecting
   me to
    [http://nicolasgaillard.com/wordpress/wp-login.php](http://nicolasgaillard.com/wordpress/wp-login.php)

Viewing 15 replies - 1 through 15 (of 20 total)

1 [2](https://wordpress.org/support/topic/locked-out-loop/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/locked-out-loop/page/2/?output_format=md)

The topic ‘Locked-out loop’ is closed to new replies.

## Tags

 * [locked out](https://wordpress.org/support/topic-tag/locked-out/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * In: [Localhost Installs](https://wordpress.org/support/forum/localhost-installs/)
 * 20 replies
 * 2 participants
 * Last reply from: [Jeff Clark](https://wordpress.org/support/users/jclark32/)
 * Last activity: [13 years, 3 months ago](https://wordpress.org/support/topic/locked-out-loop/page/2/#post-3541842)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
