2010-12-01 223 views

回答

47

上面的代碼將不會工作,因爲缺少$和使用return命令較差。上面的代碼適用於Nginx,包括0.8.54版本。下面

格式是: DesiredURL 實際URL Nginx_Rule

他們必須是內location/{}

http://example.com/notes/343 
http://example.com/notes.php?id=343 

rewrite ^/notes/(.*)$ /notes.php?id=$1 last; 

http://example.com/users/BlackBenzKid 
http://example.com/user.php?username=BlackBenzKid 

rewrite ^/users/(.*)$ /user.php?username=$1 last; 

http://example.com/top 
http://example.com/top.php 

rewrite ^/top?$ /top.php last; 

複雜,並進一步

http://example.com/users/BlackBenzKid/gallery 
http://example.com/user.php?username=BlackBenzKid&page=gallery 

rewrite ^/users/(.*)/gallery$ /user.php?username=$1&page=gallery last; 
+1

@其他大聲笑讚賞的客氣話。大多數信息都在Nginx Wiki上,並且緩慢地變化。nginx似乎在文檔和資源方面變得更加統一和集中。 – TheBlackBenzKid 2013-03-25 10:00:22

2

試試這個,

server { 
    server_name www.myweb.com; 
    rewrite ^/like/(.*) http://www.myweb.com/item.php?itemid=$1 permanent; 
}