Rehasher Caerdydd
Rehasher Caerdydd

Reputation: 91

How to put the GET parameter in nginx rewrite rule?

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

Upvotes: 6

Views: 6151

Answers (1)

Rehasher Caerdydd
Rehasher Caerdydd

Reputation: 91

Fixed it :)

Solved with

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

Upvotes: 3

Related Questions