Skip to content

Instantly share code, notes, and snippets.

@un1ko85
Created January 6, 2016 08:01
Show Gist options
  • Save un1ko85/9f7889b96de3cf449b69 to your computer and use it in GitHub Desktop.
Save un1ko85/9f7889b96de3cf449b69 to your computer and use it in GitHub Desktop.
Rewrite URI with nginx and php-fpm. I have faced the problem that REQUEST_URI parameter is not changed on nginx rewrite rule. After some research I have found solution with replacing $request_uri variable.
server {
listen 80;
server_name site.dev;
index index.php;
root /Users/balkon_smoke/Sites/site.dev/web;
error_log /Users/balkon_smoke/Sites/site.dev/logs/error.log;
access_log /Users/balkon_smoke/Sites/site.dev/logs/access.log;
location / {
try_files $uri $uri/ /index.php;
}
# save and check current $request_uri
set $request_url $request_uri;
if ($request_uri ~ ^/categories/view/(.*)$ ) {
# change it if condition is true
set $request_url /?category=$1;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
# replace it with modified
fastcgi_param REQUEST_URI $request_url;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
}
}
@skul87
Copy link

skul87 commented Dec 8, 2021

worked for me.
8 hours I find this workaround 🤪
thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment