2013-12-20 111 views
0

我想重写所有的HTML文件到Nginx的PHP文件。所以我在我的nginx conf文件中输入了下面的规则。Nginx重写HTML文件重写规则到PHP不工作

location ~ \.html$ 
{  rewrite (.*).html$ /$1.php; 
} 

但它没有效果,所以我试图把重写规则inbelwo位置,但即使这不起作用。

location/{ 
    rewrite (.*).html$ /$1.php; 
    rewrite admin/$ /admin/index.php; 
    rewrite ([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/$ /productlist.php?cat=$1&subcat=$2; 
    rewrite ([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)$ /productlist.php?cat=$1&subcat=$2&brand=$3; 
    rewrite ([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)/buy/$ /productdetails.php?cat=$1&subcat=$2&product=$3&id=$4; 
    rewrite ([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([0-9]+)/buy$ /productdetails.php?cat=$1&subcat=$2&product=$3&id=$4; 
    rewrite admin/internalattacment/(.*) /download.php/$1; 
    rewrite admin/report_bug/(.*) /download.php/$1; 
} 

但是,当我把这样的重写规则它拾起nginx的

location ~ .*.()$ { 
    rewrite (.*).html$ /$1.php; 
} 

有人可以告诉我为什么重写规则不是从第一2处捡到?

回答

0

我认为你的错误是在位置。

location ~ \.html$ 

只匹配 “html的”,而不是 “anything.html” 尝试

location ~ /(.*).html$ 
+0

它为你工作? – Pixou

+0

nopes ..它没有奏效。对于php也是如此,即“location〜\ .php $”工作正常。 – zer0Id0l