/ / Format von htaccess in nginx ändern - .htaccess, nginx

Ändern Sie das Format von htaccess in nginx - .htaccess, nginx

Ich habe einen Apache-Server mit der folgenden htaccess-Datei:

RewriteCond %{HTTP_HOST}  ^.*$ [NC]
RewriteRule   ^test/$([^/]+)/([^/]+.php)$  test/$2?VIRTUAL_DIRECTORY_NAME=$1 [L,QSA]

RewriteCond %{HTTP_HOST}  ^.*$ [NC]
RewriteRule   ^test/([^/]+)/(.*)$  $1/$2 [L]

Und ich versuche, es für Nginx Server zu konvertieren. Ich kann nicht herausfinden, wie man virtuelles Verzeichnis in korrektes Format umwandelt. Dies ist meine Nginx-Konfigurationsdatei:

server {
listen 80;
listen 443 ssl;
server_name admin.dev;
root "/home/vagrant/admin";

index index.html index.htm index.php;

charset utf-8;


rewrite_log on;

location /api/ {
rewrite ^/api/(.*)$ /api.php?$1 last;
}

location /res_partners/ {
rewrite ^res_partners/$([^/]+)/([^/]+.php)$  res_partners/$2?VIRTUAL_DIRECTORY_NAME=$1 last;
}


location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }

access_log off;
error_log  /var/log/nginx/admin.dev-error.log error;

sendfile off;

client_max_body_size 100m;

location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_intercept_errors off;
fastcgi_buffer_size 16k;
fastcgi_buffers 4 16k;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
}

location ~ /.ht {
deny all;
}

ssl_certificate     /etc/nginx/ssl/admin.dev.crt;
ssl_certificate_key /etc/nginx/ssl/admin.dev.key;
}

Irgendeine Hilfe? Vielen Dank

Antworten:

0 für die Antwort № 1

Die erste Regel scheint umzuschreiben /test/$something/somescript.php zu /test/somescript.php?VIRTUAL_DIRECTORY_NAME=$something und diese sind wörtlich $ Zeichen. Ihre location ~ .php$ { ... } Der Container stimmt bereits mit jedem URI überein, der mit endet .php. Die erste Regel kann also oben im Container platziert werden:

location ~ .php$ {
rewrite ^/test/$([^/]+)/([^/]+.php)$ /test/$2?VIRTUAL_DIRECTORY_NAME=$1&$args break;
...
}

Die zweite Regel scheint umzuschreiben /test/somedir/something zu /somedir/something (woher something ist kein PHP-Skript).

Dies kann mit einem Präfixstandort erreicht werden:

location /test/ {
rewrite ^/test/([^/]+)/(.*)$ /$1/$2;
}