2012-02-27 52 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