Forward slash between subpages

Discussion in 'PHP' started by James_DG, Jan 8, 2014.

  1. #1
    Wondering how to have a forward slash between a main page and its subpages.

    Current outcome mywebsite.com/page1-subpage.php
    Desired outcome: mywebsite.com/page1/subpage.php

    When trying to use a slash in this bit of code gives me an error message: "/".$page->url

    Full code below
    if($page->parent >1){
    $l = getParentById($page->parent,$pages);
    $page->url = remove_accents($l->title)."/".$page->url;}
    When using the original "_" or a "-", everything works just fine.

    Function (in case this may be useful)
    function remove_accents($string)
    {

    $table = array(
    'Š' => 'S', 'š' => 's', 'Ð' => 'Dj', 'ð' => 'dj', 'Ž' => 'Z', 'ž' => 'z', '?' => 'C', '?' => 'c', '?' => 'C', '?' => 'c',
    'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'A', 'Ç' => 'C', 'È' => 'E', 'É' => 'e',
    'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ñ' => 'n', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O',
    'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'Þ' => 'B', 'ß' => 'Ss',
    'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'a', 'ç' => 'c', 'è' => 'e', 'é' => 'e',
    'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'o', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o',
    'ô' => 'o', 'õ' => 'o', 'ö' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ý' => 'y', 'ý' => 'y', 'þ' => 'b',
    'ÿ' => 'y', '?' => 'R', '?' => '?',
    );

    $string = strtr($string, $table);
    $string = strtolower($string);
    $string = preg_replace('#[^a-z0-9/]+#', '-', $string);
    $string = trim($string, '-');
    return $string;
    }

    Can somebody help me out please? Creating the pages is not an issue. I can view the frontpage and "page 1" without any problems. Only when trying to view "subpage".

    I guess this quite an easy issue. Thanks in advance!
     
    James_DG, Jan 8, 2014 IP
  2. stephan2307

    stephan2307 Well-Known Member

    Messages:
    1,277
    Likes Received:
    33
    Best Answers:
    7
    Trophy Points:
    150
    #2
    so you take all this time to write this but you don't give us the error message?
     
    stephan2307, Jan 9, 2014 IP
  3. James_DG

    James_DG Greenhorn

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #3
    500 Internal server error. Only when trying to load the subpage in the browser, so: mywebsite.com/page1/subpage1. No problems when loading the frontpage or "page 1". No problems either when creating the page.

    When changing "/".$page->url into "-".$page->url or back to the original "_".$page->url, no problems seem to occur.

    EDIT
    It seems to be a problem regarding the web server's configuration. A rewrite rule would do to the trick. But I guess there's no standard/universal rewrite rule for a subpage structure based on forward slash mapping?
     
    Last edited: Jan 9, 2014
    James_DG, Jan 9, 2014 IP
  4. Philbeng

    Philbeng Well-Known Member

    Messages:
    36
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    100
    #4
    Search google for front controller and simple mvc.
    By the looks of it you need to create a array by exploding the incoming request on "/" then you can work the rest of your script from there.
     
    Philbeng, Jan 9, 2014 IP