• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

[Solved] Block Nginx Rewrite URL For Sub Directory

Kepala Suku

Web & Mobile Developer
Staff member
#1
I want to route all request inside subdirectory named portal to index.php file inside that directory. The concept is index.php handle all of url requeststed using sparated classes. For example if i created class user then we could access url like this: host/portal/user . So, i want to make the subdirectory portal to be base url (host/portal).

This url router framework i used: Files · lab · Ahmad Budairi / URLRouter · GitLab

After i browse to the internet for a while, i found this answer. That is just add these lines into block we used to handle this.
NGINX:
location /portal{
    try_files $uri $uri/ /portal/index.php?$uri&$args;
}
And then, the configuration inside index php should look like below lines.

PHP:
new Page(array(
    'rw_base' => 'portal',
        'lang_dir' => HOMEDIR.'/incl/bahasa',
        'lang_def' => 'id_ID',
    'db_dsn' => "mysql:host=$DB_HOST;dbname=$DB_NAME",
    'db_user' => $DB_USER,
    'db_pswd' => $DB_PASS
));