routing

Discussion in 'Programming/Scripts' started by Kemp, Apr 17, 2026.

  1. Kemp

    Kemp Member

    Hi,

    I have setup a routing system using php and nginx, as follows:

    index.php

    <?php

    $request = $_SERVER['REQUEST_URI'];

    switch ($request) {

    case '':
    case '/':
    require __DIR__ . '/directory1/index.php';
    break;

    case '/view/one':
    require __DIR__ . '/directory2/index.php';
    break;

    }

    --

    I have added the following to nginx directives in ISPConfig:

    location / {
    try_files $uri $uri/ /index.php?$args;
    }

    --

    When I go to domain.com/view/one it's loading the /directory1/index.php file instead of /directory2/index.php

    Thank you!
     
  2. pyte

    pyte Well-Known Member HowtoForge Supporter

    Wouldn't this be much easier?`

    Code:
    location = / {
        rewrite ^ /directory1/index.php last;
    }
    
    location = /view/one {
        rewrite ^ /directory2/index.php last;
    }
    
    location / {
        try_files $uri $uri/ =404;
    }
     

Share This Page