'URL paths to query params in NGINX
I want to convert an Apache 2.4 configuration to NGINX. I found that NGINX does not pay attention to the htaccess...
I have an Application that uses this URL structure https://app.com.ar/admin/configuracion/lalala
where configure and lala are actually variables that look like path, but are used as query params in PHP.
The original configuration in Apache is this
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?page=$1 [L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$ index.php?page=$1§ion=$2 [L]
RewriteRule ^([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$ index.php?page=$1§ion=$2&id=$3 [L]
I found a site that converted it to an NGINX rule but it didn't work, it left me this
location / {
if ($script_filename !~ "-d"){
rewrite ^/([A-Za-z0-9-]+)/?$ /index.php?page=$1 break;
}
rewrite ^/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$ /index.php?page=$1§ion=$2 break;
rewrite ^/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)?$ /index.php?page=$1§ion=$2&id=$3 break;
}
In conclusion, I need to have urls like this: https://app.com.ar/admin/configuracion/lalala
and in NGINX to be able to decompose it so that it can know how to direct it to the app with a format like this /index.php?page=$1§ion=$2&id=$3 so far no luck. I wanted to ask if anyone has the experience and what solution I can give you!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|