gpt4 book ai didi

Nginx conf如何从$ uri中删除前导斜杠

转载 作者:行者123 更新时间:2023-12-04 07:33:31 24 4
gpt4 key购买 nike

我的Nginx conf文件:

  location / {
try_files $uri $uri/ /index.php?url=$uri;
}

## PHP conf in case it's relevant
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include /etc/nginx/fastcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}

尝试以下URL: http://example.org/login:

预期的行为:
http://example.org/index.php?url=login
实际行为:
http://example.org/index.php?url=/login

最佳答案

使用命名位置和内部重写。例如:

location / {
try_files $uri $uri/ @rewrite;
}
location @rewrite {
rewrite ^/(.*)$ /index.php?url=$1 last;
}

有关更多信息,请参见 this document

关于Nginx conf如何从$ uri中删除前导斜杠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41908851/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com