2016-07-08 59 views
0

我想將子文件夾和所有內容重定向到根域。nginx將子文件夾重定向到根域

例如:

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

我的服務器配置如下圖所示:使用htaccess的here

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 
    } 

} 

我也發現了類似的問題解決了,但怎麼能我在nginx中實現?

回答

1

一個了一些解決方案是:

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

^~修飾符確保了此前綴位置繼續,如果你要添加任何正則表達式的位置在未來優先。詳情請見this document

return指令是documented here

相關問題