Reputation:
I want to rewrite the following URL:
index.php?SOMETHING=VALUE
As
/SOMETHING/VALUE
I'm inexperienced with nginx rewrites so any help would be appreciated.
Thanks
Upvotes: 0
Views: 1133
Reputation: 2157
I've come up with a solution to your problem :
location /index.php {
if ( $args ~ "(?<PATH1>.*)=(?<PATH2>.*)" ) {
rewrite ^ /${PATH1}/${PATH2}? last;
}
}
Explanations:
if ( $args ~ "(?<PATH1>.*)=(?<PATH2>.*)" )
: captures the two relevant sections from the URL parameter, storing the values in variables PATH1
and PATH2
rewrite ^
means "rewrite the entire URI"/${PATH1}/${PATH2}
is constructing the new URI?
informs nginx
that you don't want to append the original URL parameterslast
tells nginx
to continue to follow rules after the rewriteUpvotes: 1