Created
January 6, 2016 08:01
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
worked for me.
8 hours I find this workaround 🤪
thank you