nginex rewrite url rule URL from into

June 19, 2015 1.6k views
PHP Nginx

Hi, i want to change URL from into ( )

where to write this rule?

1 Answer

Hi! First, you’ll want to find a RegEx pattern that matches /val_1/val_2 (with an optional trailing backslash): ^/(.*?)/(.*?)/?$, then you’ll want to map val1 and val2 to a query string:

rewrite ^/(.*?)/(.*?)/?$ /?var_1=$1&var_2=$2&$args

&$args appends the rest of the original query string to the request, so that for example works as expected.

Make sure you restart nginx after editing the config file.

Have another answer? Share your knowledge.