Nginx: URL rewrite with proxy_pass and URL parameters and special chars

I studied all the great posts to nginx proxy and rewrite functionality, but was unable to find a solution for my problem. So here we are. I wrote an web application with vaadin, that is able to handle the follwoing request:

http://<server>/#main/search?country=germany&type=songwriter

For SEO optimization, I want to handle "speaking" urls, like: http:///songwriter/germany. So I thought URL rewriting within the web-server is the solution. But whatever I tried, I am unable to place the hashtag within the request and to form the final solution! Here is what I tried:

  location  /songwriter/ {
        proxy_set_header Host $host;
        proxy_redirect off;
        # Option 1 - hastag is encoded
        rewrite ^/songwriter/(.+) /#main/suche?land=$1  break;
        proxy_pass http://127.0.0.1:8080; 
 }

What I get in the trace is: /%23main/suche land=berlin/. Any idea?


Solution 1:

The URL fragment is client side only and is never sent to the server. (Because the literal # is not allowed there, nginx URL encodes it.) If your web app abuses URL fragments for navigation then they can only be handled by your client side (in browser) code. Note that using URL fragments in this way is not considered good practice. You will probably have to significantly rewrite your web application to get rid of them.