protected function rewrite() {
		$routes=array();
		$aliases=&$this->f3->ref('ALIASES');
		$redirects=array();
		foreach($this->f3->get('ROUTES') as $old=>$data) {
			$route=current(current($data));//let's pick up any route just to get the URL name
			$name=@$route[3];//PHP 5.3 compatibility
			$new=$old;
			if (!($name && in_array($name,$this->global_aliases)
				|| isset($this->global_regex) && preg_match($this->global_regex,$old))) {
				if (isset($this->rules[$this->current][$name])) {
					$new=$this->rules[$this->current][$name];
					if ($new===FALSE) {
						if (isset($aliases[$name]))
							unset($aliases[$name]);
						continue;
					}
				}
				$new=rtrim('/'.$this->current.($new),'/');
				if ($this->migrate && $this->auto) {
					$redir=$old;
					if (isset($this->rules[$this->primary][$name]))
						$redir=$this->rules[$this->primary][$name];
					if ($redir!==FALSE)
						$redirects[$old]=rtrim('/'.$this->primary.($redir),'/');
				}
			}
			if (isset($routes[$new]) && $this->strict)
				user_error(sprintf(self::E_Duplicate,$new),E_USER_ERROR);
			$routes[$new]=$data;
			if (isset($aliases[$name]))
				$aliases[$name]=$new;
		}
		$this->f3->set('ROUTES',$routes);
		foreach($redirects as $old=>$new)
			$this->f3->route('GET '.$old,function($f3)use($new){$f3->reroute($new,TRUE);});
	}