WordPress.org

Ready to get started?Download WordPress

Forums

Locked-out loop (21 posts)

  1. una_s88
    Member
    Posted 1 year ago #

    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

  2. Jeff Clark
    Member
    Posted 1 year ago #

    How did you setup the redirect? Through the backend

  3. una_s88
    Member
    Posted 1 year ago #

    Yup - in the options section

  4. Jeff Clark
    Member
    Posted 1 year ago #

    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()

  5. una_s88
    Member
    Posted 1 year ago #

    I do indeed, i've got it open now - what should I be looking for?
    I really appreciate your help! Thanks!

  6. Jeff Clark
    Member
    Posted 1 year ago #

    Can you post it here?

  7. una_s88
    Member
    Posted 1 year ago #

    <?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. Your posted code may now have been permanently damaged/corrupted by the forum's parser.]

  8. Jeff Clark
    Member
    Posted 1 year ago #

    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.]

  9. Jeff Clark
    Member
    Posted 1 year ago #

    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.

  10. una_s88
    Member
    Posted 1 year ago #

    Im afraid its still re-directing.. I've changed it back to the backup.. Could it be another file?

  11. Jeff Clark
    Member
    Posted 1 year ago #

    What plugin are you using?

  12. una_s88
    Member
    Posted 1 year ago #

    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

  13. Jeff Clark
    Member
    Posted 1 year ago #

    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?

  14. una_s88
    Member
    Posted 1 year ago #

    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?

  15. Jeff Clark
    Member
    Posted 1 year ago #

    Did you do it in MAMP as well?

  16. una_s88
    Member
    Posted 1 year ago #

    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

    before it was allowing me to input the admin credentials and only then redirecting me to
    http://nicolasgaillard.com/wordpress/wp-login.php

  17. Jeff Clark
    Member
    Posted 1 year ago #

    Ok did you just migrate an existing site? Or duplicate one? That almost sounds like its not the redirect plugin but the site_url and the home_url not being correct in the db?

  18. una_s88
    Member
    Posted 1 year ago #

    I think thats exactly what it is.. My brother (who posted the first comment) tried to change the url in the options section of the wp admin backend of the MAMP site which is what set off the loop. But I havent been able to log into it to change it back... This is my first website so im sorry if (for) being really silly!
    I think I just duplicated the site

  19. Jeff Clark
    Member
    Posted 1 year ago #

    haha no problem. Ok here is what you need to do. You will need to modify this using phpmyadmin. But for a quick fix you can add this to your wp-config file.

    // add this right below where it says define('WP_DEBUG', 'false') or it might be true

    define('WP_SITEURL', 'your_domain');
    define('WP_HOME', 'your_domain');

    this will allow you to get inot your site, you will need to login to phpmyadmin and go int wp_options and change the site url and the home url manually.

    Hope this helps!!!

  20. una_s88
    Member
    Posted 1 year ago #

    Oh my god.

    You are an angel sent from the dev gods haha im in on MAMP! And my site is live on the new server too!

    THANK YOU!!

  21. Jeff Clark
    Member
    Posted 1 year ago #

    No problem!!! Glad you are up and running.

Topic Closed

This topic has been closed to new replies.

About this Topic