Well, I just changed the keyword to aaabbb.
The following means that when I visit /aaabbb/anime, I actually request /ab_anime.php
location /aaabbb/ {
rewrite ^/aaabbb/(\w+)$ /ab_.php last;
rewrite "/aaabbb/(\w+)/(\d{1,2})$" /aaabbb/?id=? permanent;
}
Then I want to make it so that when I click on it for the first time, it will bring parameters. At the same time, I can’t see it in the address bar. Then every time I refresh it, there will be no parameters.
So I checked that there is no parameter and a question mark after it, but I found it useless.
Is it because I spent $1?id=$2 myself?
Only the parameters added at the end of the address bar will disappear. However, it was of no use.
I just saw this again
rewrite ^/test.php /new permanent; //重写向带参数的地址
rewrite ^/test.php /new? permanent; //重定向后不带参数
rewrite ^/test.php /new?id=$arg_id? permanent; //重定向后带指定的参数
I don’t even know what to do... Should I write another one and use $arg? ? ?
習慣沉默2017-05-16 17:17:56
I think the questioner has complicated the issue.
Of course, I’m not sure I really understand the questioner’s needs. I’ll try to elaborate as follows:
User request/aaabbb/anime
nginx correctly parses /aaabbb.php?id=anime and returns content A to the user
The user's address bar reads /aaabbb and enjoys content A
The user refreshes the browser, directed to /aaabbb, and enjoys content B of /aaabbb.php. (Or continue reading content A)
There is a bug here. When the request is /aaabbb/anime, the address bar will change to /aaabbb/anime#xxxxxx at most. The one before # will not change, and the one after # will be a hash. If you want to change the address bar to /aaabbb, you must have a redirect action.
My thoughts are as follows: (If you adopt the answer, please comment on the incorrect content in my solution)
nginx rewrite strategy is rewrite ^/aaabbb/(w+)$ /redirect.php?target= last;
redirect.php writes the target into the session and returns the redirect to /aaabbb (the address bar can and can only be modified through this method)
/aaabbb/ Navigate to index.php, read the target in the session, erase (or not erase) it, and call the corresponding php file to return the content.
When refreshing /aaabbb, navigate to index.php and also respond to requests based on session.