Welcome Guest, Not a member yet? Register   Sign In
Routing not parsing " mysite.com/# "
#1

[eluser]markanderson993[/eluser]
Hello Codeigniter experts, I hope my question is simple enough. Basically, I would like my routing script to detect if the requested uri is /# and re-route the user to the home page, else carry on with another set of instructions.

Here is my code

Code:
if ($_SERVER['REQUEST_URI'] == '/#') {
    
    $route['([a-zA-Z0-9_-]+)(.*)'] = "home/index";
    
} else {

$controllers = array();



    if($controller_dir = opendir(APPPATH . 'controllers'))
    {
        while(false !== ($file = readdir($controller_dir)))
        
        {
        
            if(preg_match('/(.*?)\.php$/i',$file,$file))
            {
                $controllers [] = $file[1];
            }
        }
    }
    else
    {
        log_message('error','Could not read controllers directory at |' . APPPATH . 'controllers');    
    }

    foreach($controllers as $controller)
    {
        $route[$controller . '(.*?)'] = $controller . "$1";
    }
    
    $route['([a-zA-Z0-9_-]+)(.*)'] = "profile/index/$1";

}
#2

[eluser]richthegeek[/eluser]
probably because # isn't a valid URI character - it's used as an in-page reference within the HTML schema (ie, #hello jumps to <a name='hello'>)
#3

[eluser]markanderson993[/eluser]
Then how can I detect that character? The routing script detects if the controller exists, and if it doesn't, treats it as a user_name.




Theme © iAndrew 2016 - Forum software by © MyBB