I'm trying to do the following: There is a site where you can find a user in the format http://localhost/username
. I tried to make a rule that if there is no file on the server, then it will redirect to index.php?username=username
. But the problem is that it redirects everything, even js and css. I want to do it like this, if the file was on the server, then it would access it, and if not, then it would make a request
index.php?username=username
There is this piece of code:
rewrite ^/(.+)$ /index.php?type=userinfo&username=$1 last;
Use try_files
to determine if the file already exists, and branch to a named location containing your rewrite rule, if it does not.
For example:
location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^/(.+)$ /index.php?type=userinfo&username=$1 last;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.