2011-12-07 126 views
0

我主要使用标准nginx的设置,并使用下面的代码重写:简单的nginx重写干净的URL

rewrite ^/account/credit$ /account/credit.php$1 last; 
rewrite ^/account/credit\/$ //account/credit.php$1 last; 

基本上,这两条线,确保下列地址都是认可:

www.example.com/account/credit 
www.example.com/account/credit/ 

有没有办法将它放到一个语句中或更优雅地使用它?

我在考虑类似

rewrite ^/account/credit(\/)?$ /account/credit.php$1 last; 

但是,这并不工作,因为它添加/到地址的末端时会将错误的水平。 //看起来有点不雅。

这是什么地方的样子:

location/{ 
    try_files $uri $uri/ /index.php; 
} 

回答

1

添加到您的conf:

location ^~ /account/credit { 
    rewrite^/account/credit.php last; 
}