如何将htaccess转换成NGINX?

时间:2017-10-09 12:04:26

标签: .htaccess nginx

请告诉我如何在此示例中将htaccess转换为NGINX。

<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(js|css|jpeg|jpg|gif|png|ico)(\?|$) - [L,NC,R=404]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

1 个答案:

答案 0 :(得分:0)

Apache使事情看起来有点复杂。但是Nginx中的相同配置非常简单

root /var/www/html;

location ~* \.(js|css|jpeg|jpg|gif|png|ico)(\?|$) {
   try_files $uri =404;
}

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

location ~ \.php {
   # <your fastcgi php handling config>
}