【问题标题】:nginx Redirect subfolder to root domainnginx 将子文件夹重定向到根域
【发布时间】:2016-11-11 02:19:39
【问题描述】:

我想将子文件夹和所有内容重定向到根域。

例如:

http://www.example.com/ubb/ 将重定向到http://www.example.com

我的服务器配置如下:

server {
    listen 80 default_server;

    root /home/vishant/devcenter/wava-v1.1/HTML;
    index index.html index.htm;

    # Make site accessible from http://localhost/
    server_name baetter.l;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to displaying a 404.
            try_files $uri $uri/ =404;
            #proxy_pass         "http://127.0.0.1:3000";
            # Uncomment to enable naxsi on this location
            # include /etc/nginx/naxsi.rules
    }

}

我发现使用 htaccess here 解决了类似的问题

但是我如何在 nginx 中实现呢??

【问题讨论】:

    标签: nginx url-rewriting nginx-location


    【解决方案1】:

    许多解决方案之一是:

    location ^~ /ubb/ {
        return 302 /;
    }
    

    ^~ 修饰符确保如果您将来要添加任何 正则表达式位置,此 前缀位置 将继续优先。详情请见this document。

    return 指令是documented here。

    【讨论】:

      猜你喜欢
      • 2017-05-10
      • 2014-08-29
      • 2012-12-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-09
      • 1970-01-01
      相关资源
      最近更新 更多