【问题标题】:Nginx Rewrite Paths to Base URLNginx 重写路径到基本 URL
【发布时间】:2016-12-21 16:18:38
【问题描述】:

我正在尝试配置 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

我尝试了aliasroot,但无法让它们工作。

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

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

【问题讨论】:

    标签: php redirect nginx


    【解决方案1】:

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

    server {
        rewrite ^/path(/.*)$ $1 last;
    
        # Your location blocks go here.
    }
    

    阅读official docs了解更多信息。

    【讨论】:

      猜你喜欢
      • 2019-08-27
      • 1970-01-01
      • 1970-01-01
      • 2016-11-27
      • 2023-04-01
      • 2017-07-05
      • 2023-04-11
      • 2022-11-03
      • 2022-11-22
      相关资源
      最近更新 更多