Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 将格式从htaccess更改为nginx_.htaccess_Nginx - Fatal编程技术网

.htaccess 将格式从htaccess更改为nginx

.htaccess 将格式从htaccess更改为nginx,.htaccess,nginx,.htaccess,Nginx,我有一个apache服务器,其htaccess文件如下: RewriteCond %{HTTP_HOST} ^.*$ [NC] RewriteRule ^test/\$([^/]+)/([^/]+\.php)$ test/$2?VIRTUAL_DIRECTORY_NAME=$1 [L,QSA] RewriteCond %{HTTP_HOST} ^.*$ [NC] RewriteRule ^test/([^/]+)/(.*)$ $1/$2 [L] 我正在尝试将其转换为nginx

我有一个apache服务器,其htaccess文件如下:

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

RewriteCond %{HTTP_HOST}  ^.*$ [NC]
RewriteRule   ^test/([^/]+)/(.*)$  $1/$2 [L]
我正在尝试将其转换为nginx服务器。 我不知道如何将虚拟目录转换为正确的格式。 这是我的nginx配置文件:

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;
}
有什么帮助吗?
谢谢

第一条规则似乎将
/test/$something/somescript.php
重写为
/test/somescript.php?虚拟目录名称=$something
,这些是文字
$
字符。您的
位置~\.php${…}
容器已匹配任何以
.php
结尾的URI。因此,第一条规则可以放在该容器的顶部:

location ~ \.php$ {
  rewrite ^/test/\$([^/]+)/([^/]+\.php)$ /test/$2?VIRTUAL_DIRECTORY_NAME=$1&$args break;
  ...
}
第二条规则似乎将
/test/somedir/something
重写为
/somedir/something
(其中
something
不是php脚本)

这可以通过前缀位置实现:

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