nginx将子文件夹重定向到根域

时间:2016-07-08 13:27:13

标签: nginx url-rewriting nginx-location

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

例如:

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中实现?

1 个答案:

答案 0 :(得分:1)

许多解决方案之一是:

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

如果您以后要添加任何正则表达位置^~修饰符可确保此前缀位置继续优先。有关详细信息,请参阅this document

return指令为documented here

相关问题