NGINX重写htaccess规则

时间:2018-10-28 16:50:59

标签: .htaccess nginx mod-rewrite

我正在尝试为NGINX规则重写htaccess规则,但返回了ERR_TOO_MANY_REDIRECTS。有谁知道我要去哪里错了? 我正在使用docker在NGINX上运行容器。

APACHE HTACCESS

bit.ly/2SttwyP

#example
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L,QSA]

# Installer
RewriteRule ^install/?$ install.php [L,QSA]

# Static Pages
RewriteRule ^static/([^/]+)/?$ static.php?url=$1 [L,QSA]

# Contacts
RewriteRule ^contacts/?$ contact.php [L,QSA]   

NGINX

bit.ly/2SttwyP
#example
server {
index index.php;
listen 80;
server_name localhost;
error_log  /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /code-admin;
location / {
      if (-e $request_filename){
        rewrite ^/install/?$ /install.php last;
      }
      rewrite ^/([^/]+)/?$ /profile.php?username=$1 last;
      rewrite ^/([^/]+)/([^/]+)/?$ /profile.php?username=$1&view=$2 last;
      rewrite ^/([^/]+)/([^/]+)/([^/]+)/?$ /profile.php?username=$1&view=$2&id=$3 last;
    }

    location /static {
      rewrite ^/static/([^/]+)/?$ /static.php?url=$1 last;
    }

    location /contacts {
      rewrite ^/contacts/?$ /contact.php last;
    }
    location ~ \.php$ {
      fastcgi_split_path_info ^(.+\.php)(/.+)$;
      fastcgi_pass php:9000;
      fastcgi_index index.php;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param PATH_INFO $fastcgi_path_info;
     }

   }

0 个答案:

没有答案