Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to put the GET parameter in nginx rewrite rule?

Tags:

nginx

get

rewrite

I'm very new to nginx and just working with the rewrite rule

I want my domain http://example.com/database/view.php?id=1

to show as http://example.com/database/id/

with the GET parameter showing in the url where "id" is, is that possible?

I have attempted this :

 rewrite ^/database/$arg_id? /database/view.php?id=[1-9]* last;

and

location @database {
     rewrite ^/view/(.*) /view.php?id=$1&$args last;
     }

and they failed resulting in example.com/database/view/51 as a 404

like image 652
Rehasher Caerdydd Avatar asked Oct 19 '22 17:10

Rehasher Caerdydd


1 Answers

Fixed it :)

Solved with

rewrite ^/view/(.*)/ /database/view.php?id=$1&$args last;
like image 72
Rehasher Caerdydd Avatar answered Oct 22 '22 20:10

Rehasher Caerdydd