Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End PHP Switch/Case and the Dreaded Unclean URLs

  • This topic is empty.
Viewing 4 posts - 61 through 64 (of 64 total)
  • Author
    Posts
  • #129027
    CrocoDillon
    Participant

    You aren’t giving me much to work with.

    Try debugging yourself by placing echos and var_dumps on crucial places (where things might go wrong) so you know where and why things go wrong. I recommend `var_dump($page)` right before your switch since that seems to be the problem.

    #129039
    rpotterjr
    Participant

    I think I may just go ahead and handle the error page through .htaccess

    #130520
    Haasboy
    Member

    Hi there

    I have a solution to your problem:

    In your .htaccess file ensure you have the following:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . index.php [L,QSA]

    Then go to your index.php and add the following:

    list($path) = explode('?', $_SERVER);
    //Remove script path:
    $path = substr($path, strlen(dirname($_SERVER))+1);
    //Explode path to directories and remove empty items:
    $pathInfo = array();
    foreach (explode('/', $path) as $dir)
    {
    if (!empty($dir))
    {
    $pathInfo[] = urldecode($dir);
    }
    }

    if (count($pathInfo) > 0)
    {
    //Remove file extension from the last element:
    $last = $pathInfo[count($pathInfo)-1];
    list($last) = explode('.', $last);
    $pathInfo[count($pathInfo)-1] = $last;
    }

    Do a print_r on $pathInfo will show you everything within the URL

    Now you make all your URLS point:
    http://localhost/

    /index/

    #130521
    Haasboy
    Member

    Sorry the above should be:

    http://localhost/<dir>/index/<page&gt;

Viewing 4 posts - 61 through 64 (of 64 total)
  • The forum ‘Back End’ is closed to new topics and replies.