将一些规则从.htacess转换为NGINX

时间:2017-04-03 05:19:26

标签: .htaccess nginx

我正在尝试将一些.htaccess规则转换为NGINX,但它并不是很顺利。我必须爬到这里寻求帮助:(〜Paypal啤酒给任何解决它的人。

我尝试了一些在线转换器,但代码看起来很乱,我不太明白它在做什么。我希望转换的规则:

# Rewrite any calls to html|json|xml|atom|rss
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.+)\.(html|json|xml|atom|rss)$ $1/ [L]

# Rewrite any calls to /render to the image resizer
RewriteCond %{REQUEST_URI} render/
RewriteRule ^render/. app/parsers/slir/ [L]

# Rewrite routes to application index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ index.php?/$1/ [L,QSA]

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

我相信它已经整理好了。在NGINX server {}块中,我包括以下内容:

location / {
  if (!-e $request_filename){

    # Rewrite any calls to html|json|xml|atom|rss if a folder matching * exists
    rewrite (.+)\.(html|json|xml|atom|rss)$ $1/ last;

    # Rewrite any calls to /render to the X3 image resizer
    rewrite ^/render/. /app/parsers/slir/ last;

    # Rewrite routes to X3 application index.php if they are non-existent files/dirs
    rewrite ^(.*)$ /index.php?$1 last;
  }
}

https://gist.github.com/mjau-mjau/6dc1948284c90d167f51f1e566a8457b

相关问题