Welcome Guest, Not a member yet? Register   Sign In
codeigniter 4 dynamic url rewrite with nginx and subdirectory controllers
#1

I have setup a codeigniter 4 project on an nginx server. I have used subdirectories in the Controllers folder. I am trying to use dynamic rewriting to generate SEO friendly URLs but I always get 404 errors.
I want to rewrite the following:
example.com/india/school/permalink -> example.com/india/school/details?p=permalink

My nginx config for example.com:
Code:
server {

    server_name example.com;

    root /var/www/example.com;


    index index.html index.htm index.php;


    location / {

            try_files $uri $uri/ /index.php;

    }


    location ~ \.php$ {

        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_index index.php;

        include /etc/nginx/fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $request_filename;
        fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;

    }

    rewrite ^/india/school/([a-zA-Z0-9-]+)$ /india/school/details?p=$1 last;

    location ~ /\.ht {

        deny all;

    }
}
I have also tried Codeigniter routes but they are also giving 404 errors:

Code:
$routes->get('/india/school/(:any)', 'india/school/details?p=$1');

Please guide me on how to get the following rewrite to work.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB