Nginx [SOLVED]: nginx rewrite part of url with ? mark Home › Forums › Nginx › Nginx [SOLVED]: nginx rewrite part of url with ? mark Tagged: nginx, url-rewriting Viewing 2 posts - 1 through 2 (of 2 total) Author Posts December 31, 2017 at 2:08 am #36724 Anonymous Question I’m serving a website with nginx as a proxy for apache. I have a problem with rewrite module. http://example.com/foo/bar/url?someparam=1&otherparam=2 I need to rewrite from /foo/bar/url?someparam=1&otherparam=2 to /foo/bar/url2?someparam=1&otherparam=2 I found it problematic, since it’s not /foo/bar/url/someparam, but it’s only a part of text, i need to rewrite in dynamic url’s. I was trying: rewrite ^(.*)url(.*)$ $1url2$2; but i’m getting error 500 on that. How can i do that? December 31, 2017 at 2:08 am #36725 Anonymous Answer In your rewrite statement, the new URI also matches the regular expression pattern. This will cause a redirection loop that ends with a 500 response. You need to make the regular expression more specific so that the new URI does not match. Also, the nginx uses a normalised URI when processing rewrite statements, that does not include the ? and the query string that follows it. So your statement could be simplified as follows: rewrite ^(.*)url$ $1url1; The rewrite directive will automatically append any ? and query string in the original URI. See this document for more. The URI that Source: https://stackoverflow.com/questions/47996862/nginx-rewrite-part-of-url-with-markAuthor: Richard SmithThis work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. Author Posts Viewing 2 posts - 1 through 2 (of 2 total) You must be logged in to reply to this topic.