2016-12-21 80 views
2

我正在嘗試配置Nginx,以便所有到http://domain.com/path的請求都被重寫爲http://domain.com/Nginx重寫路徑到基本URL

我不想重定向,因爲我希望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/; 
} 
+0

爲什麼這個問題標籤爲「.htaccess」,當它是關於一個'nginx' http服務器? – arkascha

+1

對不起,我標記錯了! – Charles

回答

1

rootalias是爲了從一個特定的目錄服務文件不重寫URL。您應該使用rewrite

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

    # Your location blocks go here. 
} 

閱讀official docs獲取更多信息。