1

community, I have a Problem and I can't find a solution. I have a website running in which you can open things. You can use the path: https://localhost/open/index.htmp?id=1234 (or without the index.html in the URI). I want to open it throughout the path https://localhost/open/1234, so I set up a NGINX rewrite-rule:

rewrite "^/open/(?!\?id=.*)(.{1,})$" /open?id=$1 permanent; (I also tried last instead of permanent) 

This rule, redirected me many times, so my path looked like /open/?id=&id=&id=&id=&id=1234 I also tried:

try_files $uri $uri/ /?id=$request_uri 

None of them worked. What have I done wrong?

1 Answer 1

1

You do not need and cannot use the (?!\?id=.*) part in the rewrite directive, as Nginx uses a normalised URI when matching location, try_files and rewrite directives.

You could focus the regular expression to only match numeric IDs, for example:

rewrite ^/open/(\d+)$ /open/?id=$1 permanent; 

The regular expression operator + is the same as {1,}.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.