2012-02-27 96 views
5

我已經成功地大部分轉換,但我掙扎了一下這兩個 -需要幫助轉換的Apache2重寫規則nginx的

RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,QSA,L] 

RewriteRule !^(media/(.+)|favicon.ico|robots.txt|sitemap.xml|sitemap-main.xml)$ index.php 

將不勝感激手,如果有人是nginx的重寫忍者:)

回答

6

此:

RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,QSA,L] 

將被轉換爲:

rewrite ^/(.+)/$ http://$http_host/$1 permanent; 

這:

RewriteRule !^(media/(.+)|favicon.ico|robots.txt|sitemap.xml|sitemap-main.xml)$ index.php 

將被轉換爲:

rewrite /!^(media/(.+)|favicon.ico|robots.txt|sitemap.xml|sitemap-main.xml)$ /index.php; 

你也可以使用:

if ($rule_0 = ""){ 
    rewrite ^/(.+)/$ http://$http_host/$1 permanent; 
} 
if ($rule_0 = ""){ 
    rewrite /!^(media/(.+)|favicon.ico|robots.txt|sitemap.xml|sitemap-main.xml)$ /index.php; 
} 

文檔:http://wiki.nginx.org/HttpRewriteModule

來源:http://www.anilcetin.com/convert-apache-htaccess-to-nginx/

+0

謝謝 - 欣賞它。我會鼓勵你......但我還沒有足夠的聲望! – 2012-02-27 12:13:39

+1

你可以投票,你也可以接受答案:http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – 2012-02-27 23:49:58

+0

啊好的謝謝,已經接受 - 我是新的對此明顯。 – 2012-02-28 09:00:50