Sample Header Ad - 728x90

NGINX rewrite rules not working

-1 votes
1 answer
7603 views
I am playing with NGINX rewrite rules, but no matter what I do, things wont work. The current link: - /tutorials/index.php?article=2 How I want it - /tutorials/2 My - current - NGINX rewrite conf/rule: location / { try_files $uri $uri/ =404 /index.php?$args; rewrite ^/tutorials/([0-9]+)$ /tutorials/index.php?article=$1 last; } What am I doing wrong here? --- My NGINX configuration file: server { # Hide php extension: ".php" if (!-e $request_filename) { rewrite ^(.*)$ /$1.php; } # Redirect to HTTPS if ($scheme = http) { return 301 https://$host$request_uri ; } # Access rule(s) location / { try_files $uri $uri/ =404 /index.php?$args; } location ~ ^/tutorials/([[:digit:]]+)$ { rewrite ^ /tutorials/index.php?article=$1 last; } # Enable: PHP FPM location ~ \.php$ { if ($request_uri ~ /tutorials/index\.php) { return 302 $scheme://$host/tutorials/$arg_article; } # Allow user execution of PHP try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php/php7.0-alpha.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; client_max_body_size 5M; } }
Asked by blade19899 (577 rep)
Aug 27, 2017, 05:54 PM
Last activity: Aug 29, 2017, 08:06 AM