gpt4 book ai didi

php - Nginx 重写基本 URL 的路径

转载 作者:行者123 更新时间:2023-12-04 11:37:24 27 4
gpt4 key购买 nike

我正在尝试配置 Nginx,以便对 http://domain.com/path 的所有请求被改写为 http://domain.com/ .

我不想重定向,因为我希望 URL 仍然显示原始路径。

示例重写:

http://domain.com/path/index.php         -> http://domain.com/index.php
http://domain.com/path/category/books -> http://domain.com/category/books
http://domain.com/path/books.php?q=harry -> http://domain.com/books.php?q=harry

我试过 alias root 但我无法让他们工作。
location /path
{
root /var/www/html/;
}

location /path
{
alias /var/www/html/;
}

最佳答案

rootalias旨在提供来自特定目录的文件而不是重写 URL。您应该使用 rewrite .

server {
rewrite ^/path(/.*)$ $1 last;

# Your location blocks go here.
}

阅读 official docs了解更多信息。

关于php - Nginx 重写基本 URL 的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41267349/

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