Aim: To rewrite url's into a application compatible format

Progress: I have a rewrite from domain root that is working fine, however when I add /foo/ or /bar/ I just get a 404 as it tries to match that location within my config.


http://domain.com/ # Working fine

http://domain.com/foo/ # getting 404 - i assume it is failing to match location

I have the application url which I have added $request_uri to the end, however I want to be able to pass the /foo/ or /bar/ into the url to have it work correctly.

I have tried $request_body $request_uri$1 and varies combinations, however no luck just a 404.

How would I go about doing this? Which $variable do I need to pass into url?

An example of the url below. Not the exact one, but hopefully enough to get an idea.

location / {
    rewrite ^/$ pt/Wondering?virtual-webr00t=http://foobar.com&pagename=123/Dispatcher&url-path=$request_uri` last;

location /pt/Wondering {

        proxy_pass http://domain.com;
        proxy_set_header  X-Real-IP  $remote_addr;
        proxy_redirect off;
        proxy_buffering off;
        proxy_set_header        Host            $host;
        proxy_set_header        X-Real-IP       $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;

        root    html;


Your problem is that you are using the below

rewrite ^/$   # Starts with / and ends with /

When you should be using

rewrite ^/ # start with / and accepts anything afterwards

The difference is the regex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.